1

i am hoping you can help,i am wondering is there a way i can populate the account contact roles, and it populates the contract,opportunity contact roles automatically

For example In the scenario below image "ACCOUNT CR" is the contact roles on the client test1, they would like these contacts roles to be poplated on image "CONTRACT CR"

Looking forward to your response

ACCOUNT CR

CONTRACT CR

1

Consider to implement an after insert /(Update) trigger, which queries contact roles from account-level and stores them as opportunity- / contract-contact-roles (opportunity team) records.

Here is a pseudo code implementation:

trigger OppContactRole on opportunity (after insert)
{
    Set<Id>accountIds = new Set<Id>();
    // To-Do: Collect account ids
    Map<Id, Account> accounts = new Map<Id, Account>([SELECT ID, (SELECT ContactId FROM AccountContactRoles) FROM Account WHERE ID IN :accountIds]);

    List<OpportunityContactRole> ocrs = new List<OpportunityContactRole>();
    for(Opportunity o in trigger.new)
    {
        for(AccountContactRole acr : accounts.get(o.AccountId).AccountContactRoles)
        {
            ocrs.add(new OpportunityContactRole(OpportunityId = o.Id, ContactId = acr.ContactId));
        }
    }

    insert ocrs;
}
  • Hi chrisitian . I get the following error message . Any ideas why ? Apex script unhandled trigger exception by user/organization: 00520000003CkJ4/00D20000000mJwI OppContactRole: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.OppContactRole: line 10, column 1 – Masond3 Aug 27 '14 at 12:41
  • @Masond3 please understand that my code example is pseudo code. Looks like there is a null pointer exception in line 10. (Maybe o.AccountId is empty..?) – Christian Deckert Aug 27 '14 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.