global class UpdateAccount implements
Database.Batchable<sObject>, Database.Stateful {
// instance member to retain state across transactions
global Integer recordsProcessed = 0;
global Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator(
'SELECT ID,old_acnum__c,accountnumber FROM ACCOUNT'
);
}
global void execute(Database.BatchableContext bc, List<Account> lstAccount){
// process each batch of records
List<Account> lstAccounts = new List<Account>();
lstAccounts1 = [SELECT ID,accountnumber,old_acnum__c,(SELECT ID FROM Contact) FROM ACCOUNT];
Map<ID,ID> mapAccountContactId = new Map<ID,ID> mapAccountContactId();
for ( Account account : lstAccounts ) {
for ( Account account1 : lstAccounts1 ) {
if( account.Id != account1.Id && account.old_acnum__c == account.accountnumber ){
//Some Logic
}
}
}
update contacts;
}
global void finish(Database.BatchableContext bc){
System.debug(recordsProcessed + ' records processed. Shazam!');
AsyncApexJob job = [SELECT Id, Status, NumberOfErrors,
JobItemsProcessed,
TotalJobItems, CreatedBy.Email
FROM AsyncApexJob
WHERE Id = :bc.getJobId()];
// call some utility to send email
EmailUtils.sendMessage(a, recordsProcessed);
}
}
apply some of your logic .. in this way we can do this
Is there any how will you detect that which account is related to which contact?
Let me know your scenario how you will map one account to the another account in whch you have to move contact.
Thanks,
Is there any flag in your account which tell this particular account is old or new?
apply some of your logic .. in this way we can do this
Here is the code:
Mark it as best answer if it helps you.
Thanks
Brahma