You need to sign in to do that
Don't have an account?

HOW TO Create a scheduler
I need to create a schedular which will find all opportunity whose status is lost and will create campaign for them and add their contact as campaign member.
You need to sign in to do that
Don't have an account?
I need to create a schedular which will find all opportunity whose status is lost and will create campaign for them and add their contact as campaign member.
Hi Ankit,
To schedule an apex class u need to implement Schedulable interface in ur class. Ur class will look as describe below
Pseudo code:
global class Class_Name implements Schedulable{
// method that will be called when the scheduled job runs
global void execute(SchedulableContext SC) {
// call a method that will create Campaign for lost opportunity
createCampaign();
}
// method to create Campaign for lost opportunity
public void createCampaign() {
// Logic to fetch lost opportunity ie. using SOQL
// logic to create Campaign
// batch insert
}
}
Now schedule this class using Schedule Apex button on Apex Classes page
check this out http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_scheduler.htm
first please let me know how do i create a camapgin for the lost opportunities..i did like this but its not working..
public class moveopportunity
{
List<Opportunity> selectopp;
public string campaignid1;
public string conactid;
public moveopportunity()
{
selectopp=[Select o.Id, o.CampaignId, (Select OpportunityId, ContactId From OpportunityContactRoles) From Opportunity o where Opportunity.StageName =:'Closed Lost'];
}
public void move()
{
if(selectopp!=null)
{
for(Opportunity O:selectopp)
{
O.CampaignId ='70190000000MjHs';
update O;
}
}
}
}
how will i create a campaign