0

From Trigger on inserting I am making a callout (from method1 of class A) i.e by using @future annotation and updating the field of the same object on which the trigger called, with the values acknowledged by the callout.

I want to call another method (method2 of class A) and make callouts by using the values updated earlier by method1.

The problem is, if I am calling it from the method1 after finishing the updates(DML) its throwing "you have uncommitted work pending. please commit or rollback before calling out" error if I don't make it future method and its giving the error "Future method cannot be called from a future or batch method" if I make it future.

And if do not call it from method1 and call it directly from trigger, there are two ways. One is to call it from isUpdate portion by which it will be called automatically when DML of method1 occurs and again I will get the error "Future method cannot be called from a future or batch method". Second is to call it in isInsert portion but as both method1 and method2 are future methods then they'll be called asynchronously, so if method2 is got to call first then it cannot use the values that would be updated by method1.

P.S : Is there any way to call two methods from a trigger and in both the methods I am using callouts and I want to use values in second method after first method performs DML operation?

4
  • are you getting some values from first callout that you are then passing in second callout and also using those value in record insertion?
    – User6670
    Commented Feb 9, 2020 at 19:48
  • Yes, ideal sequence is like on Insert first callout > Update > second callout.
    – Navii
    Commented Feb 9, 2020 at 20:01
  • 1
    why not let both the callout complete and then update the record?
    – User6670
    Commented Feb 9, 2020 at 20:03
  • Yup, that solves the problem. How can I miss that. Thanks!!
    – Navii
    Commented Feb 9, 2020 at 20:12

1 Answer 1

1

You can Make all the callout that need to happen first and then at the end make the DML operations that would stop the
you have uncommitted work pending. please commit or rollback before calling out

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .