Quantcast
Channel: How do I use REST API on a Trigger to populate account fields - Salesforce Stack Exchange
Viewing all articles
Browse latest Browse all 2

Answer by cropredy for How do I use REST API on a Trigger to populate account fields

$
0
0

You have a trigger looking like you are making an asynchronous (@future) to method getAPIAsyn but in fact, this method is never called.

Furthermore, even if the trigger did call this method, it executes asynchronously and the bottom of the trigger that loops through Trigger.new will execute BEFORE the @future method even starts - hence why no value in the account field.

The pattern to use is to (because triggers can't do synchronous callouts)

  • Invoke the future method with a list of accountIds taken from Trigger.newMap.keySet()
  • execute all the callouts (there are some issues here to think about with governor limits on # of callouts per transaction)
  • Do the account updating in the @future method once the callout has returned

Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>