Created
October 12, 2022 08:09
-
-
Save arun12209/fd22fcb6cae4029f45fc221fb604f8f1 to your computer and use it in GitHub Desktop.
BatchUpdateContactMailingCity class to update the contact records
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global with sharing class BatchUpdateContactMailingCity implements Database.Batchable<SObject>{ | |
global Database.QueryLocator start(Database.BatchableContext bc){ | |
String query = 'Select Id, BillingCity,(Select Id,Name, MailingCity from contacts) from Account'; | |
return Database.getQueryLocator(query); | |
} | |
global void execute(Database.BatchableContext bc, List<Account> accList){ | |
//list of contacts to update | |
List<Contact> conListToUpdate = new List<Contact>(); | |
for(Account acc: accList){ | |
for(Contact con: acc.contacts){ | |
con.MailingCity = acc.BillingCity; | |
conListToUpdate.add(con); | |
} | |
} | |
if(conListToUpdate.size()>0){ | |
List<Database.SaveResult> updateResults = Database.update(conListToUpdate,false); | |
List<SObject> objList = new List<SObject>(); | |
objList.addAll(conListToUpdate); | |
//call generic method to create the error log records | |
Util.createError(updateResults,objList,'Contact Update'); | |
} | |
} | |
global void finish(Database.BatchableContext bc){ | |
//add the finish code here | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment