/**
   * Called when "update" button is clicked.
   *
   * @param v
   */
  public void onUpdateClick(View v) {
    String objectType =
        ((EditText) findViewById(R.id.update_object_type_text)).getText().toString();
    String objectId = ((EditText) findViewById(R.id.update_object_id_text)).getText().toString();
    Map<String, Object> fields = parseFieldMap(R.id.update_fields_text);

    RestRequest request = null;
    try {
      request = RestRequest.getRequestForUpdate(apiVersion, objectType, objectId, fields);
    } catch (Exception e) {
      printHeader("Could not build update request");
      printException(e);
      return;
    }
    sendRequest(request);
  }
  private void getCase() {

    // Creating Case and save id in the running Activity

    if (activity.geteServiceAdministration() != null) {
      activity.setCaseFields(new HashMap<String, Object>());
      Map<String, Object> caseFields = activity.getCaseFields();
      caseFields.put("Service_Requested__c", activity.geteServiceAdministration().getID());
      caseFields.put("AccountId", activity.getUser().get_contact().get_account().getID());
      caseFields.put("RecordTypeId", activity.getCaseRecordTypeId());
      caseFields.put("Status", "Draft");
      caseFields.put("Type", "License Services");
      caseFields.put("Origin", "Mobile");
      caseFields.put(
          "License_Ref__c",
          activity.getUser().get_contact().get_account().get_currentLicenseNumber().getId());
      caseFields.put("isCourierRequired__c", true);
      activity.setCaseFields(caseFields);
      if (activity.getInsertedCaseId() != null && !activity.getInsertedCaseId().equals("")) {
        try {
          restRequest =
              RestRequest.getRequestForUpdate(
                  getActivity().getString(R.string.api_version),
                  "Case",
                  activity.getInsertedCaseId(),
                  activity.getCaseFields());
        } catch (IOException e) {
          e.printStackTrace();
        }
      } else {
        try {
          restRequest =
              RestRequest.getRequestForCreate(
                  getActivity().getString(R.string.api_version), "Case", activity.getCaseFields());
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      new ClientManager(
              getActivity(),
              SalesforceSDKManager.getInstance().getAccountType(),
              SalesforceSDKManager.getInstance().getLoginOptions(),
              SalesforceSDKManager.getInstance().shouldLogoutWhenTokenRevoked())
          .getRestClient(
              getActivity(),
              new ClientManager.RestClientCallback() {
                @Override
                public void authenticatedRestClient(final RestClient client) {
                  if (client == null) {
                    SalesforceSDKManager.getInstance().logout(getActivity());
                    return;
                  } else {
                    client.sendAsync(
                        restRequest,
                        new RestClient.AsyncRequestCallback() {
                          @Override
                          public void onSuccess(RestRequest request, RestResponse response) {
                            try {
                              JSONObject jsonObject = new JSONObject(response.toString());
                              activity.setInsertedCaseId(jsonObject.getString("id"));
                              // Getting other information Related to Created Case
                              try {
                                restRequest =
                                    RestRequest.getRequestForQuery(
                                        getString(R.string.api_version),
                                        SoqlStatements.getCaseNumberQuery(
                                            activity.getInsertedCaseId()));
                              } catch (UnsupportedEncodingException e) {
                                e.printStackTrace();
                              }
                              client.sendAsync(
                                  restRequest,
                                  new RestClient.AsyncRequestCallback() {
                                    @Override
                                    public void onSuccess(
                                        RestRequest request, RestResponse response) {
                                      JSONObject jsonObject = null;
                                      Utilities.dismissLoadingDialog();
                                      try {
                                        jsonObject = new JSONObject(response.toString());
                                        JSONArray jsonArray =
                                            jsonObject.getJSONArray(JSONConstants.RECORDS);
                                        JSONObject jsonRecord = jsonArray.getJSONObject(0);
                                        Log.d("resultcase", response.toString());
                                        activity.setCaseNumber(jsonRecord.getString("CaseNumber"));
                                      } catch (JSONException e) {
                                        e.printStackTrace();
                                      }
                                    }

                                    @Override
                                    public void onError(Exception exception) {}
                                  });
                              Log.d("", response.toString());

                            } catch (JSONException e) {
                              e.printStackTrace();
                            }
                          }

                          @Override
                          public void onError(Exception exception) {
                            VolleyError volleyError = (VolleyError) exception;
                            NetworkResponse response = volleyError.networkResponse;
                            String json = new String(response.data);
                            Log.d("", json);
                            Utilities.dismissLoadingDialog();
                            getActivity().finish();
                          }
                        });
                  }
                }
              });
    }
  }