trigger to find change in contact role for an opportunity

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 - https://success.salesforce.com/ideaview?id=08730000000BrdvAAC

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 http://www.soliantconsulting.com/blog/2012/08/view-triggers-salesforce-trigger-opportunity-contact-roles 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.