All Contact Names Update using Batch Apex in salesforce
Hi guys, here we are going to explain how to update all contact last name records with lastname +’salesforcecodes’.
Apex Class
global class batchContactUpdate implements Database.Batchable<sObject> {
global Database.QueryLocator start(Database.BatchableContext BC) {
String query = 'SELECT Id,lastName FROM contact';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<contact> con) {
for(contact c : con){
c.lastName = c.lastName + 'salesforce';
// to remove updated value from all records then
// we need to write 9th line with c.lastName =
// c.lastName.remove('salesforce');
}
update con;
}
global void finish(Database.BatchableContext BC) {
}
}
To check the output, call the apex class in debug Anonymous window.
on the top ==> debug || debug Anonymous window
call the class as shown in below image.