function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Saugandh KSaugandh K 

Catagorise records to Insert and Update from from bulk of data

Hi need help mates.

Here is the scenario.
The external web API process is pushing the set of 'contact' details to salesforce and I have to map it to the salesforce records. Here the incoming data contains a field called "employeeId" in each of the contact list. By using this field we have to identify if the incoming contact has to be INSERTED or UPDATED. I.e. if employee id exists, update the salesforce records with the updated values for that particular contact, else insert.

Till now I have done is sending one contact  using postman and have done the insert/update proceedure. Now I have to deal with thousands of contacts in a list to do this.

Doubt 1: 
How can I categorise the contacts that have to be inserted or updated ?

Doubt 2:
Should I use an apex class or trigger for this?
Anant KamatAnant Kamat
Since the requirement here is to either insert or updated based on the employeeId value, it is best to write a batch apex for the same. I assume that you have a bulkified api which accepts data from an external system. Hence you need to get capture the data and put in 2 lists one for insert operation and one for update operation. Its good to have 2 batch apex classes one to handle insert operation and one to handle update operations.
Saugandh KSaugandh K
@Anant Kamath Thanks mate. Any suggestion on the 'Doubt1' ?
Anant KamatAnant Kamat
I am quite confused with your question. You already know that employeeId is the key for your operations. You just need to create 2 different lists one for insert and one for update operation. Please let me know if there is confusion in the same.