1000 Account

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

public class CreateAccountsBatch implements Database.

Batchable<SObject> {
public Database.QueryLocator start(Database.BatchableContext context) {
return Database.getQueryLocator('SELECT Id , phone, Site FROM Account');
}

public void execute(Database.BatchableContext context, List<Account> scope) {


List<Account> accountsToCreate = new List<Account>();

Integer counter = 1;

for (Account a : scope) {


Account newAccount = new Account(
Name = 'NameAcc ' + counter ,
Phone = 'phone' + counter ,
Site ='NameAccSite ' + counter +'@gmail.com'
);

accountsToCreate.add(newAccount);
counter++;
}

try {
insert accountsToCreate;
} catch (Exception e) {
System.debug('Error occurred: ' + e.getMessage());

}
}

public void finish(Database.BatchableContext context) {


System.debug('Batch job completed');
}
}

//for execute
//CreateAccountsBatch batchJob = new CreateAccountsBatch();
//Database.executeBatch(batchJob, 1000); explain to me this code by detail

You might also like