New Batch#100 (10th Nov 2021) - Salesforce Admin + Dev Training (WhatsApp: +91 - 8087988044) :https://t.co/p4F3oeQagK

Wednesday, 4 September 2019

Parsing JSON Array which is in object format to List in Apex Class Salesforce

JSON Array in Js Controller -
[
{
"sObjectType":"Resource__c",
"Resource__c":"",
"Amount__c":"1000",
"Quantity__c":"5"
}
]
Apex Class Method -
@AuraEnabled
public static String saveRecs(Map<String,Object> inputMap) {
/*** Parsing JSON Array which is in object format to List<Sobject> Salesforce ***/
String rowsData = JSON.serialize(inputMap.get('records'))
system.debug('rowsData: '+rowsData);
List<Resource__c> records = (List<Resource__c>)rowsData;
/*********************************************************************/
String msg;
try {
upsert records;
msg = 'Success.';
}
catch(Exception e) {
msg = 'Error: '+e.getMessage();
}
return msg;
}

1 comment: