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
Subodh shuklaSubodh shukla 

Batch Class Not Updating Account Field

Hi,
In my batch class i have to populate Account Object field Account_Field__c with contact id when these field(field Account_Field__c) is null. I have tried above piece of code but it is not updating the field.

 
List<Contact> contactList = new List<Contact>();     
List<Account> accountList = new List<Account>();

 accountList = [Select Id,Account_Field__c from Account];  
 contactList = [Select Id from contact where AccountId in :accountList];

for(Account a:accountList){
              if(a.Account_Field__c == null)
                  for(Contact c:cntList){
                  a.Account_Field__c = c.Id;
                  accountList.add(a);
                  } 
              }
          }
update accountList;

Thanks in advance