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
Bard09Bard09 

Send Email when Opportunity Contact Roles are deleted?

I've been asked by my organization to send a notification e-mail when Opportunity Contact Roles are deleted on Closed Opportunities.

 

However, I'm 100% stymied trying to find a solution for this problem.

 

Here's what I've tried:

 

1. Apex code.  Unfortunately, OpportunityContactRole is not allowed for triggers!  So that's out.

2. Creating a Roll Up Summary field on Opportunities to roll up the total # of Contact Roles.  Unfortunately, it's not possible to roll up Contact Roles to Opportunites!

3. Creating a workflow rule.  Two problems here: first, Contact Roles aren't able to be included in Workflow rules.  Two, there is no known way to detect "isDeleted" for Workflow purposes (https://sites.secure.force.com/success/ideaView?c=09a30000000D9xtAAC&id=087300000007DvLAAU&mc=0)

 

Does anyone have any ideas-- no matter how fanciful or obtuse, that might help me implement this e-mail notification?

 

Trying to find a solution to this is driving me CRAZY!

 

Best Answer chosen by Admin (Salesforce Developers) 
Bard09Bard09

Well,

 

It's not pretty, but I've found a way to do this using nightly runs of Batch Apex/Apex Scheduler.  I've created two fields on Opportunities:

 

1. Total Contact Roles (Integer field)

2. Contact Roles In Text (Text field)

 

Then I use Batch Apex on a Nightly Basis to iterate over all Opportunities and Contact Roles, and if there is a difference between the previous days' values (stored in one of the above two fields), it sends an e-mail to the Opportunity Owner before storing the new value for the next day's run.

 

This is a laborious workaround, and the only reason I'm doing this instead of creating a new custom object is because migrating to custom objects in lieu of Contact Roles is currently off the table based on our internal business requirements.

 

Just thought I'd share what I did in case anyone has a similar problem in the future.

All Answers

Bard09Bard09

Well,

 

It's not pretty, but I've found a way to do this using nightly runs of Batch Apex/Apex Scheduler.  I've created two fields on Opportunities:

 

1. Total Contact Roles (Integer field)

2. Contact Roles In Text (Text field)

 

Then I use Batch Apex on a Nightly Basis to iterate over all Opportunities and Contact Roles, and if there is a difference between the previous days' values (stored in one of the above two fields), it sends an e-mail to the Opportunity Owner before storing the new value for the next day's run.

 

This is a laborious workaround, and the only reason I'm doing this instead of creating a new custom object is because migrating to custom objects in lieu of Contact Roles is currently off the table based on our internal business requirements.

 

Just thought I'd share what I did in case anyone has a similar problem in the future.

This was selected as the best answer
Pal2011Pal2011

I've the same issue, and I'm new to the programming.

 

Can you please share how to schedule batch apex to run nightly basis and send out an email notification to owner of the record?

 

Thanks,