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
gabe.eisnergabe.eisner 

Is it possible to set up a workflow that triggers indefinitely in the future?

Hello all you workflow exprts. I'm certain this COULD be done with Apex, but that's not what I'm trying to find out.

Upon new Account creation, I need some workflow actions to fire immediately - that part is done. THEN, I need follow up actions to fire every year on the anniversary of the creation date, forever into the future, based off that same initial WF rule. This seems like a simple request, but I've worked through the logic and I'm not sure it can be done with just workflows.

I'm pretty sure this can only be done with Apex, but I'd like to hear it from an expert. Thanks!

Gabe

V1nitV1nit

This can definitely be done using workflow rules.

Here is the logic how to do this.

Create a formula field that stores the month and day of the anniversary.

Then, in your workflow rule criteria specify this rule, if(Month(TODAY()) == AnniversaryMonth && Day(TODAY()) == AnniversaryDay).

 

This will fire the rule on the day of anniversary every year. Hope this helps.

Let me know if you need more detailed explanation.

gabe.eisnergabe.eisner

Hi, thanks! I believe your solution requires the record to be saved every year, on the anniversary date. Is that right? For example, on 01/01/2012, I saved the record, then I need it to trigger on 01/01/2013, 01/01/2014...forever into the future, WITHOUT ever touching the record in those future years. Is that possible? Thanks.

V1nitV1nit

As we are comparing the day and month of the anniversary date. You dont need to edit and save the record each year.

As it is a formula field it is calculated during runtime.

 

gabe.eisnergabe.eisner

Hey, thanks for all your help, but I ran a test last night, and it didn't work as expected.

 

Yesterday, 3/22/2012, I set the Date Joined (Date field) for 3/23/2011 (a year ago) and saved the record (WF was activated), hoping that, when midnight rolled around, the calendar date 3/23/2012 would match the anniversary formula month and date "3" and "23", and fire the rule. But, I still believe the reason it didn't work is that the record needs to be saved ON the anniversary day. I hope I'm doing it wrong, but I don't think it works. Again, I need the rule to fire this year (for example), after being saved on the same date last year. I really appreciate your help.

 

I believe my formula is correct:

 

ISPICKVAL(Account_Type__c, "Member") && Month(TODAY()) = Date_Joined_Anniversary_Month__c && Day(TODAY()) = Date_Joined_Anniversary_Day__c

sfdcfoxsfdcfox

Formulas won't get you all the way there. You'll need the following items to make this work:

 

1) A custom date field (e.g. Date Joined)

2) A custom date field (e.g. Next Anniversary); display on page not required

3) A custom check box field (e.g. Call Trigger); display on page not required

4) A time-based workflow rule

5) A trigger

 

The first field is obvious; the date they joined. The next field will be populated by the trigger. The third field will be populated by the workflow rule.

 

Now, the time-based workflow rule should have the criteria "Next Anniversary greater than today".

It should have two actions: 1) send an email notification (or whatever you'd like), and 2) a field update on the call trigger check box (set to true). Both actions should occur on the Next Anniversary date.

The trigger should have the following actions: 1) using an "after update", if the box is checked, it should 1) reset the box to unchecked, and 2) update the next anniversary field. Also, on a "before insert" trigger, it should set the next anniversary date to the next legal date in the future (but not today).

 

What will happen here is that on insert, the field will be populated and satisfy the workflow rule's conditions. This will cause the workflow rule to queue itself. On the date specified, the email will go out, and the check box will check itself. This will cause the trigger to go off as an "edit." Once here, the trigger will update the record manually, causing the workflow rule to be satisfied for the next year. This pattern will repeat ad infinitum until the date is cleared.

 

You can't update records in Trigger.new or Trigger.old, but you can clone these items and call an update command against the clones.

 

See this blog entry here from a blog entry made by a fellow developer: http://gokubi.com/archives/daily-cron-jobs-with-apex; it's the same thing you're trying to do, but with a yearly date instead of a daily date, and you're just sending an email instead of a batch job, but the idea holds.