You need to sign in to do that
Don't have an account?
Ramana123
I want to run this batch class at every weekend . an anyone help me in this..?
global class Account_Add_Opportunities implements Database.Batchable<sObject>{
List<Account> conlist = new List<Account>();
List<Opportunity> updateList = new List<Opportunity>();
global Account_Add_Opportunities (){
// Batch Constructor
}
// Start Methode
global Database.QueryLocator start(Database.BatchableContext BC){
return Database.getQueryLocator([SELECT id,Name,CloseDate,Type from Opportunity WHERE Type = 'New Business' AND StageName = 'New Opportunity' ]);
}
// Execute Logic
global void execute(Database.BatchableContext BC, List<Opportunity>scope){
conlist = [SELECT Id,Name,BillingAddress from Account where Name = 'Closed Lost Opportunities'];
System.debug('aaaaaaaaaaaaa'+conlist);
for(Opportunity opp :scope )
{
opp.StageName = 'Closed Lost' ;
for (Account acct :conlist)
{
opp.AccountID = acct.Id;
}
updateList.add(opp);
}
update updateList ;
}
global void finish(Database.BatchableContext BC){
// Logic to be Executed at finish
}
}
List<Account> conlist = new List<Account>();
List<Opportunity> updateList = new List<Opportunity>();
global Account_Add_Opportunities (){
// Batch Constructor
}
// Start Methode
global Database.QueryLocator start(Database.BatchableContext BC){
return Database.getQueryLocator([SELECT id,Name,CloseDate,Type from Opportunity WHERE Type = 'New Business' AND StageName = 'New Opportunity' ]);
}
// Execute Logic
global void execute(Database.BatchableContext BC, List<Opportunity>scope){
conlist = [SELECT Id,Name,BillingAddress from Account where Name = 'Closed Lost Opportunities'];
System.debug('aaaaaaaaaaaaa'+conlist);
for(Opportunity opp :scope )
{
opp.StageName = 'Closed Lost' ;
for (Account acct :conlist)
{
opp.AccountID = acct.Id;
}
updateList.add(opp);
}
update updateList ;
}
global void finish(Database.BatchableContext BC){
// Logic to be Executed at finish
}
}
You can schedule the class by calling the batch class I hope this below help article about that information could help you:
Below is the sample that was mentioned in the article:
>> https://www.minddigital.com/how-to-call-batch-apex-by-scheduler-class-within-salesforce/
Looking forward for your response.
Do let me know if this helps or incase if there are any questions do let me know.
Regards,
Anutej