I am exploring a way to pass a sobject to an apex class. Below is my apex class:
@RestResource(urlMapping = '/resturl/*')
global with sharing class check {
public boolean Hide {
get;
set;
}
public check(sobject__c customobject) {
Hide = false;
customobject.field1__c = false;
}
@HttpPost
global static Boolean save(sobject__c customobject) {
check objectcheck = new check(customobject);
return objectcheck.saves();
}
private saves() {
try {
// do some stuff
} catch (Exception ex) {
return false;
}
return true;
}
}
I am calling this rest method save() using a JSON request formed in workbench, which looks like this:
{
"customobject" : {
"field1__c" : "true"
}
}
Is this the right way to pass a custom Sobject in JSON with a custom field named field1__c?
In response of calling the method from workbench I do get a 200 HTTP response code, but I do get a false returned instead of true. So before I go into debugging I just want to make sure if I am passing the Sobject correctly in JSON.