I have to callout to an external API whenever a contact record has a certain field updated. The external API will only accept one record at a time, but of course I want to bulkify my code in the event that someone updates multiple contacts in Salesforce in a single transaction. What is the best way to generate separate requests to this API for each contact record that is updated? Right now I am thinking of the following basic framework, but I imagine there could be better ways.
I realize only so many callouts can be made in a single transaction, but I will only be dealing with 2 or 3 records at most.
Many thanks
public static void MakeSeparateRequests(List<Contact> Cons){
for(Contact C : Cons){
CreateMachine(C.ID);
}
}
@future(callout=true)
public static void CreateMachine(ID ContactID){
Contact C = [SELECT Name, Title, Email, Phone, Account.Name, Account.NumberOfEmployees
FROM Contact WHERE ID = :ContactID LIMIT 1];
Http http = new Http();
HttpRequest request = new HttpRequest();
etc...