How do you update a new contact with data from an external service?

257 Views Asked by At

I am using Salesforce Lightning mode and looking to use the configure not code approach. I have an external service defined.

The scenario I am trying to implment is as follows:

  1. User Creates Contact in Salesforce
  2. Automatically invoke external web service with some data from the new Contact
  3. Retrieve relevant data from the external service
  4. Update the contact with the data

My first attempt was to create a Record-Triggered Flow that was activated when a new Contact entity was created. The flow was then able to assign relevant variables before triggering an Action which invoked my external service. The problem I had with this is that the error "'You have uncommitted work pending. Please commit or rollback before calling out' error" appeared which led me to this article: https://help.salesforce.com/articleView?id=000328873&type=1&mode=1

So the problem as I understood it was that I cannot invoke an external service in a flow that is triggered by a contact creation.

ok

So then I looked at creating a Process which would invoke a Flow. The process is one that starts "When a record changes" and that record is set to be a Contact record that is created. The process then is supposed to call my Flow which will do the actual external service invocation.

  1. Am I on the correct lines with this approach?
  2. How do I pass variable information to the Flow from the Process?

Thanks for any insight

1

There are 1 best solutions below

5
On

The limitation is there because you're making a new record = you're temporarily locking the database table (or maybe not whole table, maybe just 1 row). But you can't hold the database hostage, have the operation wait up to 120 seconds until it succeeds/fails/timeouts. External system call must be independent, asynchronous operation.

In process builder there are immediate and time-based actions. Try to put your flow in time-based, even if it'll be set to 0 minutes after the contact creation. Or maybe in flows there are also ways to do similar thing, been a while since I used them for serious stuff.