You need to sign in to do that
Don't have an account?
Miller 95
Deactivating Campaigns Using Batch Scheduler
Hi Everyone,
Not sure if I am doing this right. I would like to get your opinion. I am looking to use the batch schedule to go out and look at all my active campaigns that have a end date of today and deactivate them. I have tried to use a workflow for this with no success, so this is what I have.
global class DeactivateCampaignBatch implements Database.Batchable<sObject>{
//Start Method
global Database.QueryLocator start(Database.BatchableContext BC){
String Query = 'SELECT EndDate FROM Campaign WHERE Campaign.EndDate=Today()';
return Database.getQueryLocator(query);
}
//Execute Logic
global void execute(Database.BatchableContext BC, List<sObject> scope){
List<Campaign> acamps;
acamps = [SELECT Id
FROM Campaign
WHERE IsActive = true
limit 100];
for(sObject s : scope){Campaign c = (Campaign)s;
if(c.IsActive = true){
c.IsActive=FALSE;
acamps.add(c);
}
}
update acamps;
}
global void finish(Database.BatchableContext BC){
}
}
I get an error on line 6 saying incorrect token: '('.
Please Help!!!
Not sure if I am doing this right. I would like to get your opinion. I am looking to use the batch schedule to go out and look at all my active campaigns that have a end date of today and deactivate them. I have tried to use a workflow for this with no success, so this is what I have.
global class DeactivateCampaignBatch implements Database.Batchable<sObject>{
//Start Method
global Database.QueryLocator start(Database.BatchableContext BC){
String Query = 'SELECT EndDate FROM Campaign WHERE Campaign.EndDate=Today()';
return Database.getQueryLocator(query);
}
//Execute Logic
global void execute(Database.BatchableContext BC, List<sObject> scope){
List<Campaign> acamps;
acamps = [SELECT Id
FROM Campaign
WHERE IsActive = true
limit 100];
for(sObject s : scope){Campaign c = (Campaign)s;
if(c.IsActive = true){
c.IsActive=FALSE;
acamps.add(c);
}
}
update acamps;
}
global void finish(Database.BatchableContext BC){
}
}
I get an error on line 6 saying incorrect token: '('.
Please Help!!!
All Answers
global class DeactivateCampaignBatch implements Database.Batchable<sObject>{
String Query = 'SELECT EndDate FROM Campaign WHERE Campaign.EndDate=Today';
//Start Method
global Database.QueryLocator start(Database.BatchableContext BC){
return Database.getQueryLocator(query);
}
//Execute Logic
global void execute(Database.BatchableContext BC, List<sObject> scope){
List<Campaign> acamps = new List<Campaign>();
for(sObject s : scope){Campaign c = (Campaign)s;
if(c.IsActive = true){
c.IsActive=FALSE;
acamps.add(c);
}
}
update acamps;
}
global void finish(Database.BatchableContext BC){
}
}
Thanks again for your help!