I have a requirement where I have a custom field named ClientId on my Account object. So anytime i create an Account, I need to call one API to get the value of this client Id and save/update for this Account.
I tried to create an after insert trigger on Account which will call an APEX class method. This method makes an Apex callout to get the clientiD from api end point.
Since callouts are not supported in trigger, i made the method call as Asynchronous using @future. But then I realized that future call should be void so I passed the account id in the class method and then make to api call to get clientId and then update the Account object with this value.
But now my challenge is that since future calls are asynchronous, my account update statement gets executed before I get a response back from API. How to ensure that my update account command runs after the api response is back.