You need to sign in to do that
Don't have an account?
Help me in JSON generator to check record exits
Json Body:
"clients_services": [
{
"name": "FEZ",
"active": true,
"billing_rate": "11.0",
"billing_rate_type": "of_fee"
},
{
"name": "State",
"active": true,
"billing_rate": "11.0",
"billing_rate_type": "of_fee"
},
{
"name": "WOTC",
"active": false,
"billing_rate": "11.0"
}
]
apex class:
List<Map<String, Object>> myMaps = new List<Map<String, Object>>();
List<Object> cs_results = (List<Object>) sf_result.get('clients_services');
list<Clients_Services__c> cs = [select Active__c, Active_Checkbox__c, service__c, Billing_Rate__c, Billing_Rate_Type__c,opportunity__c FROM Clients_Services__c where Opportunity__r.AccountId = :id];
for (Object res : cs_results) {
}
Here i need to check if record exits update else insert.
"clients_services": [
{
"name": "FEZ",
"active": true,
"billing_rate": "11.0",
"billing_rate_type": "of_fee"
},
{
"name": "State",
"active": true,
"billing_rate": "11.0",
"billing_rate_type": "of_fee"
},
{
"name": "WOTC",
"active": false,
"billing_rate": "11.0"
}
]
apex class:
List<Map<String, Object>> myMaps = new List<Map<String, Object>>();
List<Object> cs_results = (List<Object>) sf_result.get('clients_services');
list<Clients_Services__c> cs = [select Active__c, Active_Checkbox__c, service__c, Billing_Rate__c, Billing_Rate_Type__c,opportunity__c FROM Clients_Services__c where Opportunity__r.AccountId = :id];
for (Object res : cs_results) {
}
Here i need to check if record exits update else insert.
Follow this code:
And if you want to upsert record (insert or update), you need to make a custome field as external id and then using this field you can upsert record.
Follow this link for upsert:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_dml_examples_upsert.htm
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi