0% found this document useful (0 votes)
2 views

Global Class Campaignbatchclass Imp

This Apex class, CampaignBatchClass, implements the Database.Batchable interface to manage campaign records in Salesforce. It updates the status and active state of campaigns based on their start and end dates, categorizing them as 'completed', 'in progress', or 'planned'. The class includes methods for starting the batch process, executing the logic for each batch of records, and finishing the process without additional actions.

Uploaded by

sujatha.sirigiri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Global Class Campaignbatchclass Imp

This Apex class, CampaignBatchClass, implements the Database.Batchable interface to manage campaign records in Salesforce. It updates the status and active state of campaigns based on their start and end dates, categorizing them as 'completed', 'in progress', or 'planned'. The class includes methods for starting the batch process, executing the logic for each batch of records, and finishing the process without additional actions.

Uploaded by

sujatha.sirigiri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

global class campaignbatchclass implements Database.

Batchable<sObject> {
global Database.QueryLocator start(Database.BatchableContext BC) {
string query ='SELECT Id,Status,EndDate FROM campaign' ;
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<campaign> listcamp) {
list<campaign> listcamps = new list<campaign>();
for(campaign camp: listcamp){
campaign camp1 = new campaign();
camp1.Id =camp.Id;

if(camp.EndDate < system.today() ){


camp.Status = 'completed';
camp.IsActive = false;
//update camp1;
listcamps.add(camp1);

system.debug('camp status value =='+ camp1.Status);


}
if(camp.StartDate == system.today() ){
camp.Status = 'In Progress';
camp.IsActive = true;
listcamps.add(camp1);

}
if(camp.StartDate > system.today() ){
camp.Status = 'Planned';
camp.IsActive = false;
listcamps.add(camp1);

}
if(listcamps.size()>0){
update listcamps;

global void finish(Database.BatchableContext bc){

}
}

You might also like