You need to sign in to do that
Don't have an account?
S D
REST API for Inserting/Updating 2-3 records
Can anyone please help me with this:---
I want to only insert 3 records using POST Method. and as its not a bulk request so i am not preferring BULK API.
also as JSON does support the storage of data as array, so believe the below format is good to go for.
But am not able to understand how would this be processed further in Apex Class??? How can i pass it as a signature to the class. I tried to do and got the below error.
format of JSON :
{"merch" : [
{"name" : "Eraser1", "description" : "desc", "price" = 2, "Inventory" : 1000},
{"name" : "Eraser2", "description" : "desc", "price" = 20, "Inventory" : 9000},
{"name" : "Eraser3", "description" : "desc", "price" = 28, "Inventory" : 6000}
]}
Error:
"message" : "Unexpected parameter encountered during deserialization: merch at [line:1, column:12]",
"errorCode" : "JSON_PARSER_ERROR"
} ]
I am not sure what does this error mean??
I want to only insert 3 records using POST Method. and as its not a bulk request so i am not preferring BULK API.
also as JSON does support the storage of data as array, so believe the below format is good to go for.
But am not able to understand how would this be processed further in Apex Class??? How can i pass it as a signature to the class. I tried to do and got the below error.
format of JSON :
{"merch" : [
{"name" : "Eraser1", "description" : "desc", "price" = 2, "Inventory" : 1000},
{"name" : "Eraser2", "description" : "desc", "price" = 20, "Inventory" : 9000},
{"name" : "Eraser3", "description" : "desc", "price" = 28, "Inventory" : 6000}
]}
Error:
"message" : "Unexpected parameter encountered during deserialization: merch at [line:1, column:12]",
"errorCode" : "JSON_PARSER_ERROR"
} ]
I am not sure what does this error mean??
One tip is to use this awesome tool, and see how it generates the Apex model for you, and then see if that lines up with how you're trying to cast the JSON string. https://json2apex.herokuapp.com/
I ran your JSON through the tool, and it told me that you have to change "=" to ":". After doing that, here's what the generated apex looked like:
I am just curious to know, post this generation of Class...Do we have to us this somewhere in Saleforce. ???? as I am still getting this error,with the updated JSON request. Could you pl guide.
my POST Method looks like this:
Error now is :
to fix this issue, i have modified my class to : But it dint help :
@HttpPost
global static String createMerchandise(String merch)
{
List<Merchandise__c> tt = (List<Merchandise__c>)System.JSON.deserialize(merch, List<Merchandise__c>.class);
system.debug(tt);
return 'done'
}
Logic is you need to get the JSON data in a array parameter of Apex Class, and start consuming it.