I'm learning basics of using Rest API and using workbench to explore it .
As of now , I'm correctly able to make get Call to salesforce for e.g
/services/data/v34.0/sobjects/Account/001K00000XXXXX
is bringing me details of the record mentioned above
Now I'm testing POST via Rest API To SFDC. This is the area where I'm having problems and doubts.
My first question.
as I'm trying to create Account record via post request , is there a standard similar way, like above(which is GEt request to retrieve data) to create record and get ID back via POST ?
I tried hard to search but what I got are Salesforce articles is : this can be done by creating your own rest resource(Custom class exposed as Rest Resource like in this way
@RestResource(URLMapping = '/SingleAccounInsert/*')
Global class CreateSingleAccount {
@httpPost
Global static string CreateAcc( string nm, string Descrip, String Type, String area){
Account acc = new Account();
acc.name = nm ;
acc.Description = Descrip;
acc.Type = Type;
acc.Area__c= area;
insert acc ;
return acc.Id;
} }
Second question :
Even If try to use above rest resource and post following data to SFDC on URL :
/services/apexrest/SingleAccounInsert/
{
"name" : "Sansui Corp",
"description" : "Electronics Buys",
"Type" : "XYZ",
"Area__c" : "USA"
}
I Get below JSON PARSER ERROR
message: Unexpected parameter encountered during deserialization: name at [line:2, column:13] errorCode: JSON_PARSER_ERROR
I'm stuck now, not sure how to test POST Requests.
Articles referred :
https://developer.salesforce.com/docs/atlas.en-us.apex_workbook.meta/apex_workbook/apex_rest_2.htm
https://developer.salesforce.com/docs/atlas.en-us.apex_workbook.meta/apex_workbook/apex_rest_1.htm