function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
TechEd_ProgrammerTechEd_Programmer 

Need Help Scheduling Batch

Below is the Batch Job I have created. I am a litle fuzzy as to how to implement this in the shceduler. Can someone assist?

 

global class UpdateContactFlags implements Schedulable, Database.Batchable<sObject>{
	public string query = 'SELECT Id, Contact.Id, Campaign.Fund_s__c, Campaign.Listing_Tactic__c, Status from CampaignMember';
		
	global Database.Querylocator start(Database.BatchableContext BC)
	{
		
		return Database.getQueryLocator(query);
	}
	
	global void execute(SchedulableContext SC)
	{
		UpdateContactFlags ucfg = new UpdateContactFlags();
		database.executebatch(ucfg, 100);
	}
	
	global void execute(Database.BatchableContext BC, List<sObject> scope)
	{
	Set<id> liContIds = new Set<id>();

	for(sObject s : scope){
		CampaignMember cm = (CampaignMember)s;

		if(cm.Campaign.Fund_s__c == 'FSIC' && cm.Campaign.IsActive == TRUE && cm.Campaign.Listing_Tactic__c == 'Major Market Roadshow')
			liContIds.add(cm.Contact.Id);
		}

	//query all the contact in a single query
	List<Contact> cont = new List<Contact>();
	
	cont = [select id, Major_Market_Roadshows_Green__c from Contact where id in :liContIds and FSIC_Approved__c != NULL];
	
	for ( Contact conts : cont)
	{
		conts.Major_Market_Roadshows_Green__c = 'Y' ; 
	}

	if(cont.size() > 0)
	
	update cont;
	}
	
	global void finish(Database.BatchableContext BC){} 	
}

 Not really sure what I am missing.

 

Thank you in advance for the help.

 

Best Answer chosen by Admin (Salesforce Developers) 
souvik9086souvik9086

Yes just schedule it there for your preferred time.

 

Thanks

All Answers

souvik9086souvik9086

Call this batch apex from a schedular class

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_scheduler.htm

 

And then schedule that apex classin Schedule Apex

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

TechEd_ProgrammerTechEd_Programmer

So even though I have indicated that this is schedulable at the top of the class and have an execute funtion in the class, I still need a seperate class for it?

souvik9086souvik9086

NO. I skipped the fact that you implemented both schedulable and batch class both here.

Than you just go forward and schedule this class. It is expected to work fine.

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

 

 

TechEd_ProgrammerTechEd_Programmer

Ok so here is the stupid question. Where do I do that? 

TechEd_ProgrammerTechEd_Programmer

Found it! Ok now I feel like an idiot. Thank you for your guidance.

souvik9086souvik9086

Yes just schedule it there for your preferred time.

 

Thanks

This was selected as the best answer