Good day everyone, I am trying to sync my salesforce data and php application data. I have read an article from jeff douglas in this link http://blog.jeffdouglas.com/2009/03/16/restful-web-service-callout-using-post/ . And this is what I've use. I create an api in my php application and call that particular api every time a contact is created/updated/deleted. Below is some part of my code.
TRIGGER :
trigger AS_syncToWordPress on Contact (after delete, after insert, after update) {
if(Trigger.isInsert || Trigger.isUpdate) {
Set<Id> allInsertedId= Trigger.NewMap.keySet();
AS_httpSyncToWordpress.sendAPIRequest(allInsertedId);
}
}
CLASS :
public with sharing class AS_httpSyncToWordpress {
@future (callout=true)
public static void sendAPIRequest(Set<Id> setAllId) {
List<Contact> allContact= [Select Id,FirstName,LastName,Email FROM Contact where ID IN :setAllId];
String jsonContact = JSON.serialize(allContact);
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
Http http = new Http();
req.setEndpoint('https://this-is-a-sample-endpoint-url/v1/update_contact');
req.setMethod('POST');
req.setBody(jsonContact);
req.setCompressed(true); // otherwise we hit a limit of 32000
System.debug('REQUEST : ' + req);
try {
res = http.send(req);
System.debug('RESPONSE wew ' + JSON.deserializeUntyped(res.getBody()));
} catch(System.CalloutException e) {
System.debug('Callout error: '+ e);
System.debug(res.toString());
}
}
}
At the moment the code is running well. I can update my database when I update some random contact record in salesforce. But my question is that, if I have 100000 or more contact and some of them will update their record at the same time will I not hit governor limit specially I am using @future annotation? What are the other possible limitation I will hit? What are the best practice I need to know to implement my scenario ? I am trying to read some salesforce article about this but I did not quite understand. Please help.