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 

how to move opportunity under comapaign?

i need to  find all the opportunity whose status is "closed lost" and create a camapigjn for them...i did like this but its not working.Please rectify the error:-

  

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

}
}


}