+ Start a Discussion
Subodh shuklaSubodh shukla 

Batch Class Not Updating Account Field

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;
update accountList;

Thanks in advance