function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MlearyMleary 

Need help with Apex Trigger - Contact Role

Objective - 

custom lookup field on Invoicing object called "Billing_Contact__c."

The Billing Contact lookup field on the Invoice will populate with a Contact who is a Contact Role on the associated Opportunity that has a role of "Invoice/Billing."  

 

Any help would be appreciated!

Shivanath DevnarayananShivanath Devnarayanan

Hello,

 

If I understand your Requirement completely , you want to make sure that the contact associated with the Lookup field (custom Field) should be associated with a contact role as "Billing/Invoice" other wise you want to throw an exception.

 

Here's what I'd do.

 

In the Trigger (before update)

 

1) query the OpportunityContactRole Object where the Role is Billing/Invoice and opporuintyId is your Opp.Id as a List

2) Check if your Contact ID is in the part of OpportunityContactRole

else

Opportunity.addrror('Please select Contact with Role as billing/invoice');

 

this is a rough algorithm ..

 

do let me know if you need more info..

 

mark it as sovled if it helped you so others may find it helpful.

 

 

phiberoptikphiberoptik

I think the OP is asking the same as what I am asking in a recent question that still doesnt have an answer. Shivanath D, if you can help at all I would appreciate it.

 

We need a trigger that populates the custom lookup field with the Contact ID of the Contact assigned as a specific Contact Role. So, in my case, when a Contact is added as an Account Contact Role and assigned the Role "Budget Owner", upon save, I want this Contact to be populated in a custom lookup field on the Account object.

 

How would this trigger look?


Thank you in advance.