0

I'm running into a challenge around automatically updating Opportunities.

  • My Opportunities' names are generated by a workflow. This workflow pulls from various fields on the Opportunity object. One of these fields is a custom Primary Contact field.

  • I've written an Apex trigger on the Opportunity that automatically populates the custom Primary Contact field when a Primary OpportunityContactRole is added or deleted.

  • The problem is, the Apex trigger doesn't fire when I add/remove an OpportunityContactRole - it only fires - and therefore, the Opportunity Name only updates - once I've updated the Opportunity. I've asked our sales reps to click Edit --> Save to induce this renaming behavior.

  • I'm trying to get the Opportunity to update automatically when a Primary OpportunityContactRole is added or deleted.

  • However, I can't add Apex Triggers to OpportunityContactRoles, and moving to a custom object isn't feasible right now. Is there any way I could get the Opportunity to automatically update when adding/removing a Primary Contact?

1

I'd either create a batch job to run every half hour or so, and check for records with a changed contact role, or, replace the page the users are using to change the contact role with a visualforce page, and cause an opportunity update after updating the contact role.

Either solution should get you there, but you'll have to pick one or the other. Personally, I prefer visualforce solutions, since it turns into "when you do this, this happens", instead of "well, it should do it on its own, eventually".

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.