You can use a time-based workflow rule for this type of behavior.
- Create a workflow rule that matches the criteria you're looking for.
Example Criteria:
Opportunity:Type equals ABC AND
Opportunity:Stage equals DEF
- Add a time dependent action.
Example Action:
5 Days AFTER Last Modified Date
If you'd like to check, for example, when the last task was assigned, you'll have to use a trigger on the Task object to update the opportunity. This will trigger the time-based workflow. You could also use a custom field, such as Last Updated Activity
, and update that field via a trigger on tasks. Your action could be based on that field.
Example Trigger:
trigger updateOpportunityFromTask on Task (after insert, after update) {
map<id,opportunity> opps = new map<id,opportunity>();
for(task record:trigger.new) {
if(record.whatid != null && record.whatid.getsobjecttype() == opportunity.sobjecttype) {
opps.put(record.whatid, new opportunity(id=record.whatid, last_updated_activity__c=date.today()));
}
}
update opps.values();
}
Once you've made the workflow rule, you can provide workflow field updates, tasks, emails, outbound notifications, etc. to implement your business logic.