0

I want to write a trigger workflow that checks whether an opportunity of type x and stage y has not had activity for the last 5 days.

I could however not find any date related fields when selecting opportunity as source for my workflow.

How can I get this done?

  • 1
    Is there any reason you can't use LastModifiedDate ? – Phil Hawthorn Jul 4 '13 at 11:11
1

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.

0

In addition to Phil's recommendation, you could also use the OpportunityHistory object's SystemModstamp field, assuming you have History Tracking enabled on Opportunity (difficult to believe that wouldn't be the case). If you do, it's most likely that Related Tasks, Activities and Events would also be tracked in the History which would be captured as well, making OpportunityHistory a good object to use for your purposes. That's a dateTime field as is LastModifiedDate.

You might want to download the Object Reference PDF from Developer SF which contains information on nearly all the standard objects, their standard fields and properties for nearly every object that exists in SF.

0

I don't think you can use OpportunityHistory with workflow. However, this might work for you:

Create a new Workflow Rule on Opportunity, make it trigger when "created, and any time it’s edited to subsequently meet criteria"

Make the entry criteria a formula that says:

CreatedDate <> LastModifiedDate

You can also add && StageName <> 'Closed', or any other required criteria.

Then, add a Time-Dependent Workflow Actions, that runs "5 Days After Opportunity: Last Modified Date".

Add an action there, that sends an email, etc.

0

If you choose to use a formula for the Rule Criteria, Last Activity (the standard LastActivityDate field) is available.

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.