• vivek singh 20
  • NEWBIE
  • 30 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 3
    Replies
Example--

Contact Roles
Contact Roles Help Contact Roles Help (New Window)
Action Contact Name Company Name Email Phone Role Primary
Edit | Del Brown IBM   123123123123   Checked                                                               
Edit | Del Brown IBM   123123123123 Buyer

triger--
____________

trigger OpportunityTrigger on Opportunity (After insert)
{
    if(trigger.isAfter && trigger.isInsert)
    { system.debug('After insert');
        opportunityTriggerHandler objopportunityTriggerHandler = new opportunityTriggerHandler();
        objopportunityTriggerHandler.createNewContact(trigger.new);
    }
}
__________________________
class
-------------------------
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;
       
    }
}
Example--

Contact Roles
Contact Roles Help Contact Roles Help (New Window)
Action Contact Name Company Name Email Phone Role Primary
Edit | Del Brown IBM   123123123123   Checked                                                               
Edit | Del Brown IBM   123123123123 Buyer

triger--
____________

trigger OpportunityTrigger on Opportunity (After insert)
{
    if(trigger.isAfter && trigger.isInsert)
    { system.debug('After insert');
        opportunityTriggerHandler objopportunityTriggerHandler = new opportunityTriggerHandler();
        objopportunityTriggerHandler.createNewContact(trigger.new);
    }
}
__________________________
class
-------------------------
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;
       
    }
}