I have a batch class that should update the Contact phone number with Related Account Phone number.
But it is not working as it wont update the records. Please find my code below.
However there is no error with the code:
global class CustomBatch implements Database.Batchable<Sobject> {
global Database.QueryLocator start(Database.BatchableContext bc)
{
String query = 'select id,phone,Account.phone from Contact';
system.debug('query');
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext bc,List<Contact> Scope){
List<Contact> con = new List<Contact>();
for(Contact c:con)
{
c.Phone = c.Account.Phone;
con.add(c);
system.debug('c');
}
update con;
}
global void finish(Database.BatchableContext bc){
Messaging.SingleEmailMessage myemail = new Messaging.SingleEmailMessage();
String[] toadd = new String[]{'[email protected]'};
myemail.setToAddresses(toadd);
myemail.setSubject('BatchCompleted');
myemail.setPlainTextBody('Batch process has been completed successfully');
Messaging.sendEmail(new Messaging.Email[]{myemail});
}
}