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
Carolyn SutherCarolyn Suther 

Trigger to Send Email When No Activity in 30 Days

I'm trying to create a trigger that allows the opportunity owner and the admin to be notified when there is no activity on an opportunity in 30 days. I tried creating a workflow that looked at the number of days since last activity, but workflows trigger when an opportunity is created or edited, and I need the field "Days Since Last Activity" to be looked at everyday. Is this possible to do using triggers?
John Pipkin 14John Pipkin 14
Carolyn, 

This is not possible via Trigger. This would be accomplished by writing a Schedulable Class that runs every day. See http://www.infallibletechie.com/2012/05/apex-scheduler.html

Hope that helps
SalesFORCE_enFORCErSalesFORCE_enFORCEr
Can you explain the problem with workflow? I think it can be done using a time based workflow.
Carolyn SutherCarolyn Suther
The workflow will only trigger when an opportunity is edited or created. So if an opportunity is not edited, the workflow will not trigger after, for example, those 30 days.
John Pipkin 14John Pipkin 14
LastActivityDate does not make the record go through the save process. Workflows are only evaluated during a save process. That is why a Scheduler class is suggested. There are other declarative work-arounds, but they involve many new fields and workflows. If you are a developer, it would be highly recommended just to do the Scheduler as it is much more reliable.

Hope that helps
SalesFORCE_enFORCErSalesFORCE_enFORCEr
I am taking an example where system should notify opportunity owner when there is no activity in 30 days and status is open.
Workflow criteria will be StageName!=Closed/Won
and Send notification to owner 30 Days after LastModifiedDate. So, when you create an opportunity, this workflow will create an action to send alert after 30 days and when you update the record, system will adjust the action according to the updated last modified date.