function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
rikhilsuhas9rikhilsuhas9 

You have uncommitted work pending. Please commit or rollback before calling out..."

hi ,
i made a webservice callout using batch apex and after getting response  i am doing update operation .this is working fine for when i given scope parameter as 1 in the database.executebatch. however when i pass scope parameter  as10 it only updating 1 value and getting exception like "You have uncommitted work pending. Please commit or rollback before calling out..."   . and am doing dml operation after the callout  & based on callout response result only .
I dint get solution on developer community..
please help me in this scenario.
thanks

Best Answer chosen by Admin (Salesforce Developers) 
kiranmutturukiranmutturu
you can do 10 callouts in a single transaction, and you must do these before calling insert.

so, make the loop collect up a list of object records, then insert them after you have completed the callouts

or if your process needs first insert desperately workaround is splits the transaction into two separate Ajax processes. The first inserts the record and the second performs the callout and is able to update the newly inserted record

All Answers

kiranmutturukiranmutturu
you can do 10 callouts in a single transaction, and you must do these before calling insert.

so, make the loop collect up a list of object records, then insert them after you have completed the callouts

or if your process needs first insert desperately workaround is splits the transaction into two separate Ajax processes. The first inserts the record and the second performs the callout and is able to update the newly inserted record
This was selected as the best answer
rikhilsuhas9rikhilsuhas9

Thanks kiran  now i am able to do 10 callouts and update the collection . thanks for your time . here i have a small doubt will it handle 11 million records as we can process 10000 dml rows ?

 

thank you

kiranmutturukiranmutturu
best way of doing this batch processing using batch apex..but analyse the pros and cons according to your implementation....make use of asynchronous calls where ever it is possible...