1

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.

1 Answer 1

1

Looking at the code and assuming you are planning to load 100K records in a single day and expecting for all records to sync to an external system ,I will be worried about no of async executions allowed

enter image description here

Doing quick math assuming for the day you have no other async jobs or batches going on 250K seems to be Ideal .

In your case for 100000 records you are consuming ****1000**(100000/100) calls only which is great

You have taken care of your service to accept in bulk which is great.

2
  • .Thank you so much. When I have 100000 contact it is also very rare that they will update their record at the same time. Anyway, back to your answer. Do you mean that what I've done is correct and nothing to worry about ?
    – Hope
    Commented Mar 17, 2016 at 3:27
  • Exactly ...you are all good Commented Mar 17, 2016 at 3:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .