I went through some questions here like System.CalloutException: You have uncommitted work pending which provide answer where the callout can be split into asynchronous way.
Based on the information in below URL, https://help.salesforce.com/articleView?id=000079772&type=1
callout
insert
callout <---- fails here
I am doing below:
callout
insert (this insert is based on response from first callout, response is being used in second callout and response also gets upserted in custom object in FUTURE method)
callout
Above scenario fails even though I am trying to split the insert operation into a Future/ Queueable method. I cannot have the second callout happening in asynchronous way as the response of second callout should be presented in UI
UseCase: 1) Callout - Retrieve accesstoken - valid for next 5 hours, so u want to reuse this 2) DML - Insert the accesstoken in custom object for reusing 3) Callout - Use the retrieved access token to get the actual response and pass to UI
When my method finds there is a valid active token in database, it is going to skip step 1 from above and proceed to Step 2 and 3. This scenario works perfectly.
It fails when there is no active token found and it has to begin from Step 1.
Any suggestions ?