function readOnly(count){ }
Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
global class contactPhoneUpdate implements Database.Batchable<sObject> { List <Contact> toUpdate = new List <Contact> (); global Database.QueryLocator start(Database.BatchableContext BC) { String query = 'SELECT Id,phone,account.phone from contact'; return Database.getQueryLocator(query); } global void execute(Database.BatchableContext BC, List<contact> scope) { for ( contact c : scope) { c.Phone=c.account.phone; toUpdate.add(c); } update toUpdate; } global void finish(Database.BatchableContext BC) { } }
Try this code
Hope this helps you
If this helps kindly mark it as solved so that it may help others in future.
Thanks and Regards
please try below batch class code :
public class contactPhoneUpdateByAccPhone implements Database.Batchable<sObject> {
public Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator('SELECT id,Phone,account.Phone FROM Contact');
}
public void execute(Database.BatchableContext bc, List<Contact> contactList){
for(Contact eachContact : contactList)
{
eachContact.Phone = eachContact.account.phone;
}
update contactList;
}
public void finish(Database.BatchableContext bc){
System.debug('Successfully Update');
}
}
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Suraj