0

I'm trying to uncheck a checkbox on the opportunity object called Commitment

global class UpdateContacts implements Database.Batchable<sObject>
{
   global Database.queryLocator start(Database.BatchableContext BC )
   {
        String str = 'SELECT Id, Commitment__c FROM Opportunity WHERE IsOpen = false';
        return Database.getQueryLocator(str);

   }

    global void execute(Database.BatchableContext BC, List<Opportunity> opportunityToProcess)
     {
     List<Opportunity> opportunityList = new List<Opportunity>();
       for(Opportunity oppObj : opportunityToProcess){
                Commitment__c = true;
            opportunityList.add(oppObj);
          }
        update opportunityList;
        }
   global void finish(Database.BatchableContext BC)
    {
   system.debug('finish');     
    }    
}
2

Presumably, you're trying to set the Commitment__c field of the opportunity record. You'll want to write it like this:

oppObj.Commitment__c = false;

Where oppOb is the record you're working with, Commitment__c is the field you're working with, and "false" means to uncheck a box (per your original question). If you want to check the box, use "true" instead.

  • Which line do I need to update? What if I only want to apply this to open opportunities? – Ryan Kohne Apr 14 at 16:44
0

You are just missing the reference of using opportunity instance. Remaining all good.

  global class UpdateContacts implements Database.Batchable<sObject>
  {
  global Database.queryLocator start(Database.BatchableContext BC )
  {
      String str = 'SELECT Id, Commitment__c FROM Opportunity WHERE IsOpen = 
      false';
      return Database.getQueryLocator(str);

   }

global void execute(Database.BatchableContext BC, List<Opportunity> 
 opportunityToProcess)
 {
 List<Opportunity> opportunityList = new List<Opportunity>();
   for(Opportunity oppObj : opportunityToProcess){
            **oppObj.Commitment__c = true**;
        opportunityList.add(oppObj);
      }
    update opportunityList;
    }
  global void finish(Database.BatchableContext BC)
   {
    system.debug('finish');     
   }    
} 

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.