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
Ankit Khurana24Ankit Khurana24 

urgent:how to write schedular class to move "Closed lost " opportunities to a campaign

i need to write schedular class to move "Closed lost " opportunities to a campaign and their related contacts to campaign member..idid loike this but it is not working....please help also let me know where do i need to write system.schedule method....

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;
            }
           
        }
  }


}

 

and

 

global class scheduledMerge implements Schedulable
{
   global void execute(SchedulableContext SC)
   {
      moveopportunity M = new moveopportunity();
   }
}

 

neophyteneophyte

The easiest way to schedule a class is by the standard salesforce wizard for the same. This will get the job done in a few clicks. For accessing this, go to setup -> develop -> apex classes. Click the schedule apex button, select the class you want to schedule and when you want the class to run.

 

If for some reason, this does not let you schedule the class in a manner you want. You can use system.schedule in the developer console, the link for which can be found in the top right corner. Or from eclipse exceute the same in the exceute anonymous window.

Ankit Khurana24Ankit Khurana24

scheduling is fine:

please let me know how do i move contacts related to lost opprtunities to camaign members..because there is no direct relation between contacts and campaigns..