Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We have a scenario where we have contact roles added to an opportunity. We need to know if a contact role for a contact has changed for an opportunity. E.g John doe was an executive sponsor first for an opportunity and now John doe contact role is Influencer for the same opportunity. We need to log the old contact role and new contact roles for the contact and flag a field on the contact that the contact role changed. How can we do this and if any body can share any code snippet please? Thanks Buyan

share|improve this question
up vote 9 down vote accepted

Well, you've probably figured out by now that Triggers aren't supported on OpportunityContactRole (OCR). And, when an OCR is CRUD'd, there is no trigger that fires on the Opportunity either.

There is an idea for this -

I've seen three workarounds

  • Run a scheduled batch apex job that sweeps the Opportunities (or Contacts) and looks at their OCR and compares them to previously-saved OCRs (saved in another child sobject or possibly as a hidden long text Opportunity/Contact field as serialized JSON)

  • Create an 'on view' trigger for your standard Oppo page layout that compares the current OCR to some prior value of the OCR (saved as above). See for the code. Advantage here is that feedback to user is near immediate, subject to only how long the future method takes to run (see code in link)

  • Redo your Oppo page as a VF page with a custom component to add/delete/change OCRs. Your VF controller can then act on the before/after values and save in the Oppo/Contact.

share|improve this answer
Thanks for your reply. Option 2 on the soliant consulting blog would solve our need. – buyan kumar Aug 19 '14 at 10:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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