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
mbondmbond 

Workflow Object in Apex?

Is there a way to manipulate a Workflow's time dependent action in Apex to push the time out further?

 

Here's my scenario:  320 days after a custom date field in an Account, I need to send an email alert.  That's easy to do with Workflow.  However, if that date changes, I need the existing email alert's send date to also change.  I don't see a way to handle this with existing Workflow and Apex functionality. 

 

Does anyone know of a way?

 

Thanks,

Matt

bob_buzzardbob_buzzard

If the custom date changes, the scheduled date for the time dependent action will also change as long as the action hasn't already taken place.

 

From the Salesforce help:

 

--- snip ---

 

If you change a date field that is referenced by an unfired time trigger in a workflow rule that has been evaluated, Salesforce recalculates the unfired time triggers associated with the rule. For example, if a workflow rule is scheduled to alert the opportunity owner seven days before the opportunity close date and the close date is set to 2/20/2011, Salesforce sends the alert on 2/13/2011. If the close date is updated to 2/10/2011 and the time trigger has not fired, Salesforcereschedules the alert for 2/3/2011. If Salesforce recalculates the time triggers to a date in the past, Salesforce triggers the associated actions shortly after you save the record

 

-- snip ---

sfdcfoxsfdcfox

As long as the workflow rule is set to "When a record is created, or when a record is edited and did not previously meet the rule criteria", changing the date on your custom field will reset the queued action's date to the new calculated date (e.g. 320 days after custom field date). You shouldn't need to modify the time delay queue directly through Apex Code.