Friday, 14 September 2018

Batch Apex Example to Update Contact Email Id

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
global class ContactEmailUpdateBatch implements Database.Batchable < sObject > {

    global Database.QueryLocator start(Database.BatchableContext BC) {
        String query = SELECT Id, Email FROM Contact;
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, List < Contact > scope) {

        for (Contact a: scope) {
            a.email = a.email + .test;
        }
        update scope;
    }

    global void finish(Database.BatchableContext BC) {}
}


Executing the above batch class from the anonymous window of developer console:



1
2
ContactEmailUpdateBatch CEUB = new ContactEmailUpdateBatch();
Database.Executebatch(CEUB ,1);

No comments:

Post a Comment