You need to sign in to do that
Don't have an account?
Shaikh Rayyan
I want to copy all accounts with rating as warm to custom warm accounts object without duplication.
Global class copyWarmAccounts implements Database.Batchable<Sobject>
{
Global Database.QueryLocator start(Database.BatchableContext bContext)
{
string query = 'Select name, id, rating from account';
return database.getQueryLocator(query);
}
Global void Execute(Database.BatchableContext bContext, list<Account> batch)
{
list<warm_accounts__c> lstwac = new list<warm_accounts__c>();
for(Account acc : batch)
{
if(acc.rating == 'warm')
{
Warm_accounts__c wac = new Warm_accounts__c();
wac.name = acc.name;
wac.Rating__c = acc.Rating;
wac.Id = acc.Id;
lstwac.add(wac);
}
}
insert lstwac;
}
Global void finish(Database.BatchableContext bContext)
{
//do nothing
}
}
{
Global Database.QueryLocator start(Database.BatchableContext bContext)
{
string query = 'Select name, id, rating from account';
return database.getQueryLocator(query);
}
Global void Execute(Database.BatchableContext bContext, list<Account> batch)
{
list<warm_accounts__c> lstwac = new list<warm_accounts__c>();
for(Account acc : batch)
{
if(acc.rating == 'warm')
{
Warm_accounts__c wac = new Warm_accounts__c();
wac.name = acc.name;
wac.Rating__c = acc.Rating;
wac.Id = acc.Id;
lstwac.add(wac);
}
}
insert lstwac;
}
Global void finish(Database.BatchableContext bContext)
{
//do nothing
}
}
Please use below code:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
All Answers
Try Below Code
Points to Follow
Make Checkbox Field on Account To Check To Process Only Those Accounts Whose Rating Is Warm Once Those Accounts Gets Processsed Then Those Wil Not Be Processed Further Again Please Mark It As Best Answer If It Helps
Thank You!
Please use below code:-
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh