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

how to move lost opportunities to a campaign.:urgent
what i need to do is:make a class to to a create a campaign for all those opportunities whose status is "closed lost" and create a campaign for them also all the contacts related to that opportunity should move to campaign member.e
Step would be like this:
1.Create a camapign.
2.Identify lost opportunities
3.Identify contact related to those opportunities.
4.Put Idsof conatc into set,<map>
5.Add these conatacts to cmapaign members.
public class moveopportunity
{
List<Opportunity> selectopp;
public string campaignid1;
public string conactid;
List<CampaignMember> cmember;
public moveopportunity()
{
selectopp=[Select o.Id, o.CampaignId, (Select OpportunityId, ContactId From OpportunityContactRoles) From Opportunity o where Opportunity.StageName =:'Closed Lost'];
cmember=new List<CampaignMember>();
if(selectopp!=null)
{
for(Opportunity O:selectopp)
{
O.CampaignId = '70190000000MjHs';("how to avoid hard code")
cmember=[Select c.ContactId, c.CampaignId From CampaignMember c where CampaignId =:'70190000000MjHs'];
for(integer i=0;i<O.OpportunityContactRoles.size();i++)
{
cmember[0].ContactId= O.OpportunityContactRoles[i].ContactId ;
}
update O;
update cmember;
}
}
}
public void move()
{
}
}
please help the above code in
1Avoid.hard code the campaign..i need to create it..
2. How to fetch contacts from opportunities because opportuniti>>>account>>contact is relationship
3.how to add conatcts obtained in sets to campaign member..
.