function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
deni kurniawandeni kurniawan 

restRequest.getRequestForcreate did not work

Good morning all

I have an problem with my coding..I will create new record to object in salesforce..I use restRequest.getRequestForcreate
Nothing an error but while I check the object in salesforce nothing a new record

this is my code

public void createRecords() {

  Map<String, Object> fields = new HashMap<String, Object>();
  fields.put("Table_No__c", picker.getValue());
  try {
   restRequest = RestRequest.getRequestForCreate(
     getString(R.string.api_version), "Order__c", fields);
  } catch (Exception e) {
   // TODO: handle exception
   Toast.makeText(
     MainActivityChoiceTable.this,
     MainActivityChoiceTable.this.getString(SalesforceSDKManager
       .getInstance().getSalesforceR()
       .stringGenericError(), e.toString()),
     Toast.LENGTH_LONG);
  }
}

any someone can help me?
Thank you

Best Answer chosen by deni kurniawan
Gaurav NirwalGaurav Nirwal
Please try this code that solves your problem

private void createSFEvent()  {

        RestRequest restRequest = null;
        try {

            @SuppressWarnings("rawtypes")
            Map createEventInfo = new HashMap();

            createEventInfo.put("AccountID", addEmailET.getText().toString());
            createEventInfo.put("Description", addCommentET.getText().toString());

            Format df = DateFormat.getDateFormat(this);
            createEventInfo.put("ActivityDate", df.format(start));

            restRequest = RestRequest.getRequestForCreate(getString(R.string.api_version), "Event" , createEventInfo);

        } catch (Exception e) {
            showError(MainActivity.this, e);
            return;
        }

        client.sendAsync(restRequest, new AsyncRequestCallback() {

            @Override
            public void onError(Exception e) {
                showError(MainActivity.this, e);
            }

            @Override
            public void onSuccess(RestRequest request, RestResponse response) {

                try {

                    Log.d("APITest", "success entered");

                } catch (Exception e) {
                    showError(MainActivity.this, e);
                }

            }
        });
    }


All Answers

Gaurav NirwalGaurav Nirwal
Please try this code that solves your problem

private void createSFEvent()  {

        RestRequest restRequest = null;
        try {

            @SuppressWarnings("rawtypes")
            Map createEventInfo = new HashMap();

            createEventInfo.put("AccountID", addEmailET.getText().toString());
            createEventInfo.put("Description", addCommentET.getText().toString());

            Format df = DateFormat.getDateFormat(this);
            createEventInfo.put("ActivityDate", df.format(start));

            restRequest = RestRequest.getRequestForCreate(getString(R.string.api_version), "Event" , createEventInfo);

        } catch (Exception e) {
            showError(MainActivity.this, e);
            return;
        }

        client.sendAsync(restRequest, new AsyncRequestCallback() {

            @Override
            public void onError(Exception e) {
                showError(MainActivity.this, e);
            }

            @Override
            public void onSuccess(RestRequest request, RestResponse response) {

                try {

                    Log.d("APITest", "success entered");

                } catch (Exception e) {
                    showError(MainActivity.this, e);
                }

            }
        });
    }


This was selected as the best answer
deni kurniawandeni kurniawan

Ok Matthews..thank you

it work 

Gaurav NirwalGaurav Nirwal
Thanks deni kurniawan