0

I have to do a callout, but before doing the callout I need to update the cases and use the values from the cases' fields in the request body and then do the callout. I cannot do DML before callout. Trying to do future/Queueable on update of cases still led me to You have uncommitted work pending. So I have to do future/Queueable on the callout. But my callout logic has return statements while future/Queueable return void.

The only solution I found out was:

  1. assigning new values to the cases' fields without calling update
  2. use them as request body
  3. get response from callout
  4. update cases
  5. continue with callout logic

Is there a way to return from future/Queueable?

0

I would suggest to use to Chain Queueable jobs:

  1. "updating the cases' fields" -> do in synchronous context
  2. "use them as request body" -> pass to Queueable job #1 as param. You can use wrapper object if needed.
  3. "get response from callout and update cases" -> in Queueable job perform the callout and get a response, update cases. Pass control to the Queueable job #2
  4. "continue with callout logic" -> execute Queueable job #2

Here is a quick snippet that might help

public class AsyncExecutionExample implements Queueable {
    public void execute(QueueableContext context) {
        // Your processing logic here       
 
        // Chain this job to next job by submitting the next job
        System.enqueueJob(new SecondJob());
    }
}
1
  • the cases are updated in the front end. thats the reason why I am doing a return of the cases after the callout. – nSv23 Jan 15 at 20:04

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.