2

The logic for my code is: look for a Lead with a specific email; if none exists, create a Lead with that email address.

The problem is that this code is running pretty frequently for the same email address: every 10 seconds. It seems that it takes Salesforce longer to create the Lead and update its servers because I'm seeing doubles of the Lead. Subsequent requests correctly find that a Lead with that email address already exists.

I'm wondering how long I should wait for the creation (or update or delete) process to finish, and whether there's another REST API endpoint other than the one for FIND that takes this issue into consideration.

Thanks!

2

FIND leverages the search index. This can take several seconds up to several minutes to index the data. Instead, consider running a query instead. It will find any records that have been committed to the database, in real time. In most cases, this should be sufficient. Check out the documentation for performing a query in the REST API Developer's Guide. Once a DML operation completes, and a status result has been returned to the client, that record is queryable. In other words, DML operations are synchronous. Search indexing, in contrast, is asynchronous, and explains the delay you're seeing in regards to using a FIND call.

  • I have a follow-up question to your answer. Is there a way I can perform a SELECT that will return all Leads and Contacts that match an email address? I'd like to minimize the number of API requests I'm making, so I'd ideally do this search in 1 query, but I can't seem to figure out how to do that. – user3827303 Oct 27 '14 at 21:05
  • Not in a single query, no. In fact, you shouldn't be trying to do this client-side at all, as there will always be race conditions between when you query and when you insert/update the record. Instead, implement this as a database trigger with row locks. – sfdcfox Oct 27 '14 at 21:31
0

First I would like to get a little bit more info from you. Are you querying in from an external application using the salesforce provided rest endpoints or are you using ApexRest?

WRT the time it takes to update, that will be dependent on the Triggers and Workflow rules that are setup in that specific org. Does an Insert/Update call to the lead record do anything else? You can go to the debug log in salesforce and look to see what is happening that is taking so long to complete. Go to setup -> monitoring -> debug logs

  • No Apex code. All purely using the REST API endpoints for standard objects; no custom fields, no custom objects. I'd just be updating company name. – user3827303 Oct 27 '14 at 18:25
0

There is no way to identify SLA to finish update / delete operation. One way could be to call REST API in @future on after Update or after Delete However only 10 future request is allowed in single transaction. Other way, if you dont need realtime then use Scheduled Bulk class.

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.