I have a class which implements Database.Batchable, Database.AllowsCallouts. In the execute method, when I am using just update lstOpportunity the update goes through but when I use Database.update(lstOpportunity, false) it does not work.

Here's my code:

public class MyBatchable implements Database.Batchable<Opportunity>, Database.AllowsCallouts {
  public Iterable<Opportunity> start(Database.BatchableContext bc){
      // Do a soql on opportunity.
      return lstOpportunity;
  public void execute(Database.BatchableContext bc, List<Opportunity> lstOpportunity){
    if(lstOpportunity != null && lstOpportunity.isEmpty() == false){
      // Do a callout and save the result in a lstOpportunityToUpdate

    if(lstOpportunityToUpdate != null && lstOpportunityToUpdate.isEmpty() == false){
     // Here if I use "update lstOpportunityToUpdate;" it works 
     // but "Database.update(lstOpportunity, false)" does not work.


Am I doing anything wrong?

  • 1
    What does "not work" mean here? Do you receive an error? – David Reed Feb 28 '19 at 0:53
  • 2
    // but "Database.update(lstOpportunity, false)" does not work. this line in your code performs a partial save and does not throw an exception if there are any errors. You must handle the errors in the return value yourself or they silently pass on through. – Mark Pond Feb 28 '19 at 0:55
  • What I meant to say was, the update DML operation does not go through. If the there were any errors, the update DML operation would rollback entire transaction which is not happening. – Json Bourne Shell Feb 28 '19 at 20:20
  • 1
    As Mark Pond states, the false parameter means that no exception is thrown and thus no rollback occurs. See documentation. – David Cheng Mar 2 '19 at 6:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.