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

Why can't I insert OpportunityContactRole for existing Opportuntiy?
I want to insert OpportunityContactRole into an existing Opportunity in a controller extended from opportunity standard controller.
Below is my code:
/* Set CampaignId */ opportunity.CampaignId = sCampaignId; OpportunityContactRole oppContactRole = new OpportunityContactRole(ContactId=sId, OpportunityId=opportunity.Id, IsPrimary=false, Role='Economic Decision Maker'); insert oppContactRole; ... stdController.save();
After I insert oppContactRole, it has ID but I can not access
this object and it is not displayed in opportunities contact roles list after the whole action is over.
There is no any exception throwed.
BTW: I can update or delete the existing opportunity's OpportunityContactRole.
I am sorry to say that there are something wrong with my code in that I remove this contact role later by myself.
Hi,
Try with this code
opportunity op = [select id,name from opportunity where name=:'opportunity name'];
contact c=[select id,name from contact where id=:'some contact record id'];
opportunitycontactrole pcr= new opportunitycontactrole();
pcr.contactid=c.id;
pcr.opportunity=op.id;
pcr.IsPrimary=true;
pcr.Role='CEO';
insert pcr;
were you able to achieve this - because now I have a same kind of requirement... please let me know.