I have a trigger that calls a method that does a http callout. This method is annotated as @future(callout=true). Once this callout is successful, I need to return a status flag so I can do further processing depending if this flag is true or false. Since this future method has to be void, how can I achieve this - any suggestions? thanks!
2 Answers
Perform Post-API-Response processing in the future method itself, Since it's an asynchronous process, It will never return value to the calling method (Trigger in this context).
You cannot return a value from future
method, as it is asynchronous and salesforce just queues up the job to run in future. Job gets executed at a later time when system resources become available
What you can do here is have a platform event inserted from the future , with the status value, and subscribe to that platform event via Apex.
This way as soon as the platform event is inserted, your Apex platform event listener will listen to that and you can run your logic after that.