// records to be updated received from json jsonBody = '[{"count__c":"445", "downloads__c":"340"}, {"count__c":"440", "downloads__c":"240"}]'; List<Data__c> dList = (List<Data__c>) System.JSON.deserialize(jsonBody, List<Data__c>.class); countList has unique count__c values, say: 445,440 // to use in the IN clause. // Querry parent for those plan ids in daily data json List<Parent__c> parentList = [SELECT Id, Name FROM Parent__c WHERE count__c IN :countList]; List<Data__c> dataToInsert = new List<Data__c>(); // Loop through dList - inner loop for(Data__c dRecords : dList) { for(Parent__c parentRecords : parentList) { if(dRecords.count__c == parentRecords.count__c) { dRecords.downloads__c = parentRecords.downloads__c ; dataToInsert.add(dRecords ); } } } insert dataToInsert;
Salesforce API user for integrations. Create a specific api user account for integrations. This way records can be updated and created with this user account than any other logged in user's account?
To make the integration user the context user for the apex initiated records inserts, etc., you need to run the Apex class as your integration user, which means:
- Authenticating a remote system calling the API as the integration user.
- Scheduling a Scheduled Apex class while logged in as the integration user.
- Doing a one-off test of an Apex class while logged in as the integration user.
Client applications that access Salesforce through the API must first log in as a Salesforce user for authentication. Create a special user in your organization, solely for integration purposes. That way, if an actual user leaves your organization, you'll always have a user with the correct permissions available.
Learn more here: https://help.salesforce.com/s/articleView?id=000331470&type=1