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
Ivan WinzerIvan Winzer 

Is batch job updating records

So i was in need of scheduling a Apex job to run on scheduler. Few folks helped me out and i got the classes to work. But now im wondering if they are actually updating records. I ask becasue the class below is to update a checkbox on the object each time its run, but when i check my history i dont see any changes. And i should see it becaue once the class checks the box i have a work flow to uncheck it but im not seeing any of this in the history, yet the job keeps completing and saying it batched 61 batches. Is there a way i can see a log of whats being updated or does the code below not actually update anything?
global class WineClubCronJobBatch implements Database.Batchable<sObject> 
{ 
   global Database.QueryLocator start(Database.BatchableContext BC) 

  { 
    String query ='Select Id, Tenure_Cron_Job_Schedule__c From Wineclub_Membership__c Where Active__c=True'; 
      return Database.getQueryLocator(query); 
  } 

    global void execute(Database.BatchableContext BC, List<sObject> scope) 

   { 
       List<Wineclub_Membership__c> listToUpdate = new List<Wineclub_Membership__c>(); 
        for( Wineclub_Membership__c a: (List<Wineclub_Membership__c> ) scope) 
        {  
            if(a.Tenure_Cron_Job_Schedule__c = False ) 
            {    
                a.Tenure_Cron_Job_Schedule__c = True;  
                listToUpdate.add(a); 
            }    
        } 
        if(listToUpdate.size() > 0) 
       { 
            update(listToUpdate);  

       } 

   } 
   global void finish(Database.BatchableContext BC){ 
  } 

}

 
Best Answer chosen by Ivan Winzer
Amit Chaudhary 8Amit Chaudhary 8
Please try below code. Line Number 16 should be if(a.Tenure_Cron_Job_Schedule__c == False )

 
global class WineClubCronJobBatch implements Database.Batchable<sObject> 
{ 
   global Database.QueryLocator start(Database.BatchableContext BC) 

  { 
    String query ='Select Id, Tenure_Cron_Job_Schedule__c From Wineclub_Membership__c Where Active__c=True'; 
      return Database.getQueryLocator(query); 
  } 

    global void execute(Database.BatchableContext BC, List<sObject> scope) 

   { 
       List<Wineclub_Membership__c> listToUpdate = new List<Wineclub_Membership__c>(); 
        for( Wineclub_Membership__c a: (List<Wineclub_Membership__c> ) scope) 
        {  
            if(a.Tenure_Cron_Job_Schedule__c == False ) 
            {    
                a.Tenure_Cron_Job_Schedule__c = True;  
                listToUpdate.add(a); 
            }    
        } 
        if(listToUpdate.size() > 0) 
       { 
            update(listToUpdate);  

       } 

   } 
   global void finish(Database.BatchableContext BC){ 
  } 

}

// You need two equal signs (==) to test equality
NOTE     == is used to check equality
and = is used to assign the value.

Please let us know if this will help you.

Thanks
Amit Chaudhary

All Answers

JeffreyStevensJeffreyStevens
you can certinally add a system.debug to your code, and it will log your debug messages.  for example - after line 15 - you could att
system.debug('Wineclub_Membership__c='+a);
and it should put a log entry in your log, with the values of all the fields selected for the object.

I would also look at line 16 - I think the syntax should be ... if(a.Tenure_Cron_Job_Schedule__c == false) ....
 
Ivan WinzerIvan Winzer
Thanks for the reply Jeffrey.

One question i have is you mentioned that line 16 should have == but doesnt that mean not equal or does that men equal and should i also update line 18 as well for the make true?
Amit Chaudhary 8Amit Chaudhary 8
Please try below code. Line Number 16 should be if(a.Tenure_Cron_Job_Schedule__c == False )

 
global class WineClubCronJobBatch implements Database.Batchable<sObject> 
{ 
   global Database.QueryLocator start(Database.BatchableContext BC) 

  { 
    String query ='Select Id, Tenure_Cron_Job_Schedule__c From Wineclub_Membership__c Where Active__c=True'; 
      return Database.getQueryLocator(query); 
  } 

    global void execute(Database.BatchableContext BC, List<sObject> scope) 

   { 
       List<Wineclub_Membership__c> listToUpdate = new List<Wineclub_Membership__c>(); 
        for( Wineclub_Membership__c a: (List<Wineclub_Membership__c> ) scope) 
        {  
            if(a.Tenure_Cron_Job_Schedule__c == False ) 
            {    
                a.Tenure_Cron_Job_Schedule__c = True;  
                listToUpdate.add(a); 
            }    
        } 
        if(listToUpdate.size() > 0) 
       { 
            update(listToUpdate);  

       } 

   } 
   global void finish(Database.BatchableContext BC){ 
  } 

}

// You need two equal signs (==) to test equality
NOTE     == is used to check equality
and = is used to assign the value.

Please let us know if this will help you.

Thanks
Amit Chaudhary
This was selected as the best answer
Ivan WinzerIvan Winzer
Thanks Amit & Jeffrey that works. I was able to run a report on history and saw that the field was updated and that i was marked as last modified at the time of hte scheduled apex run. Only think i cant seem to find now are the debug log files but the reports in SF show me what i needed to know.

You guys are awesome thanks for your help.

Ivan