2

I am integrating Contacts from an external system and the volume is 40-70k per day. I need to update the contacts in Salesforce, but only if they already exist (using emailId as the key).

If I query salesforce for every record, it will exceed API limits. I am thinking of developing a custom APEX web service which checks If the record exists then update it and I think this service can take up to 200 records at a time. Is there any other better way to accomplish this without writing a custom web service?

  • out of curiosity, why do you have to ignore the contacts that already exist? wasn't sure if was to avoid duplicates in which upsert with email id as the key is the easiest way to go – Ralph Callaway Sep 23 '14 at 20:19
  • @Ralph, I need to ignore the contcats that are NOT present in salesforce. – sdondeti Sep 23 '14 at 20:23
2

I would do this in a webservice, much cleaner.

An alternative "hack" might be to create a new object, lets say "StagedContact". Then, use standard salesforce API to push your contacts into this custom object. Then, write a trigger on this object as after insert to validate if the emailID exists or not. If yes, add to the standard contacts, if no delete the staged contact or don't do anything. Possibly cleaned the staged contact time to time or use it to enrich your contact data later on, etc.

  • Thanks. The option#2 seems a good idea..As you mentioned, need to clean up from time to time. – sdondeti Sep 23 '14 at 20:36
2

Depending on the capabilities of your integration, you might first consider making the changes on that side. If you have somewhere to store the email ids you've seen on the integration, you can simplify that by just checking your local store while preparing the update.

To populate the list, even with very large orgs you should still be able to pull down all the contacts using the bulk api without exceeding the API limits. However, depending on your orgs data volumes that may not be terribly efficient. The web services API has getUpdated and getDeleted calls which you can use to update your cache. You might also take a look at the Streaming API if you want to update the cache in real time.

There are probably a number of hack-ish approaches with triggers that you might also consider. For example, adding a trigger that fails all inserts for the integration user (make sure the integration allows for partial DML success). @JeremyButler also suggested using a intermediate object with a trigger to copy it over to contacts if it meets your criteria.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.