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

Hi sir, when we make a trigger on opportunity & fill all field then only one contact role made but when we fill contact filled and opportunity then contact role make 2 value how i solve it
Example ----When we fullfill contact then opporetunity then two contact role
Action Contact Name Company Name Email Phone Role Primary
Edit | Del Mark Sze informgroup.com mark.sze@informgroup.com Checked
Edit | Del Mark Sze informgroup.com mark.sze@informgroup.com Buyer Checked
_______________________________________________________________________________________
When we fill oportunity then only one contact role ___
Action Contact Name Company Name Email Phone Role Primary
Edit | Del Mark Sze informgroup.com mark.sze@informgroup.com Checked
How i solve it and i want to only one contact role in under opportunity
Trigger-------------
________________________
trigger OpportunityTrigger on Opportunity (After insert)
{
if(trigger.isAfter && trigger.isInsert)
{ system.debug('After insert');
opportunityTriggerHandler objopportunityTriggerHandler = new opportunityTriggerHandler();
objopportunityTriggerHandler.createNewContact(trigger.new);
}
}
________________________________
Class is _______________________________
Public class opportunityTriggerHandler
{
public void createNewContact(List<Opportunity> triggerNew)
{
List<OpportunityContactRole> lstOppContactRole = new list<OpportunityContactRole>();
if(triggerNew != null && triggerNew.size() > 0)
{
for(Opportunity objOpp : triggerNew)
{
if(objOpp.Buyer__c != null)
{
OpportunityContactRole objOppContactRole = new OpportunityContactRole();
objOppContactRole.ContactId = objOpp.Buyer__c;
objOppContactRole.OpportunityId = objOpp.ID;
objOppContactRole.Role = 'Buyer';
lstOppContactRole.add(objOppContactRole );
}
}
}
if(lstOppContactRole.size() > 0)
insert lstOppContactRole;
}
}
Action Contact Name Company Name Email Phone Role Primary
Edit | Del Mark Sze informgroup.com mark.sze@informgroup.com Checked
Edit | Del Mark Sze informgroup.com mark.sze@informgroup.com Buyer Checked
_______________________________________________________________________________________
When we fill oportunity then only one contact role ___
Action Contact Name Company Name Email Phone Role Primary
Edit | Del Mark Sze informgroup.com mark.sze@informgroup.com Checked
How i solve it and i want to only one contact role in under opportunity
Trigger-------------
________________________
trigger OpportunityTrigger on Opportunity (After insert)
{
if(trigger.isAfter && trigger.isInsert)
{ system.debug('After insert');
opportunityTriggerHandler objopportunityTriggerHandler = new opportunityTriggerHandler();
objopportunityTriggerHandler.createNewContact(trigger.new);
}
}
________________________________
Class is _______________________________
Public class opportunityTriggerHandler
{
public void createNewContact(List<Opportunity> triggerNew)
{
List<OpportunityContactRole> lstOppContactRole = new list<OpportunityContactRole>();
if(triggerNew != null && triggerNew.size() > 0)
{
for(Opportunity objOpp : triggerNew)
{
if(objOpp.Buyer__c != null)
{
OpportunityContactRole objOppContactRole = new OpportunityContactRole();
objOppContactRole.ContactId = objOpp.Buyer__c;
objOppContactRole.OpportunityId = objOpp.ID;
objOppContactRole.Role = 'Buyer';
lstOppContactRole.add(objOppContactRole );
}
}
}
if(lstOppContactRole.size() > 0)
insert lstOppContactRole;
}
}
As i assume that buyer__c is lookup to contact object and created trigger in my org .Its working fine for me Try This code..
If this answer helps you,Please mark it as best answer to help others :)
Thanks
All Answers
As i assume that buyer__c is lookup to contact object and created trigger in my org .Its working fine for me Try This code..
If this answer helps you,Please mark it as best answer to help others :)
Thanks
my problem is i want only one contact role in under opportunity when we full fill all field then only on contact role but when we make contact then opportunity then make 2 contact role how i solve it
Action Contact Name Company Name Email Phone Role Primary
Edit | Del Mark Sze informgroup.com mark.sze@informgroup.com Checked
Edit | Del Mark Sze informgroup.com mark.sze@informgroup.com Buyer Checked
_______________________________________________________________________________________
When we fill oportunity then only one contact role ___
Action Contact Name Company Name Email Phone Role Primary
Edit | Del Mark Sze informgroup.com mark.sze@informgroup.com Checked