1

I have the following requirement.

Update the date field for a specific set of opportunities every day.

My first thought process is to build a batch/scheduled apex solution and schedule it to run every 24 hrs.

I would like to know whether the same requirement can be implemented via a non-code solution like process builder or a workflow ?

4

You can theoretically do this entirely through configuration, but your mileage may vary. Conceptually, here's how you might do this:

Custom Object

First, build a custom object with a single date/time field to trigger from, and probably a checkbox to control process builder.

Flow/Apex Code

Next, build a Flow that performs a query for the records you want to update, and performs the update. Normal DML and governor limits apply, so if you expect to exceed this limit, you will have to resort to Apex Code. If that happens, you might want to write the entire thing in Apex Code, but practically speaking, you could just execute a batch job from the process builder while retaining the rest of this configuration.

Process Builder

After that, build a process on the custom object that triggers the flow or Apex Code when the box is checked, then creates a new custom object record with the next intended fire time (e.g. 24 hours later).

Workflow Rule

Finally, build a workflow rule that evaluates when the checkbox is not checked, and has a time-based field update that goes off when the date/time value is reached. The field update should check the box.

Kick Off

Now, you just create a custom object record with the next (initial) start time with the box unchecked. Once the date/time value is reached, the workflow rule will update the checkbox, which kicks off the process, which executes the flow, which will update the opportunities, and then schedule the next execution time.

While this is a pretty interesting mental exercise, an experienced developer could probably write up the initial code in less time than it'd take to point-and-click your way through this design, and without the limitations inherent at every step of the way. The advantage, of course, is that it can be later changed without future deployments.


As an alternative, if you know the records that need to be regenerated daily, you can build a set of two workflow rules. The first rule triggers when a box is not checked, and reevaluates the workflow rules. It has three actions, one of which is to update the field you want to update, and the other is to check the box, and the third is to set a future date/time value. The second rule triggers when a box is checked, and fires 24 hours after the future date/time value specified, unchecks the box, and reevaluates rules. This causes perpetual updates to occur on those records indefinitely. As per the other solution, one initial "touch" is required to kick off the cycle.

1

You could potentially use Scheduled Actions in Process Builder, or Time-Dependent Workflow Actions in Workflow Rules.

This could be OK for new records, but you'd have to make a change to all your existing records to trigger the initial workflow rule and schedule the action. If down the track you wanted to change the rule/action, you would also have to activate the new version and then move all the existing records out of the prior version and into the new one.

There are also some limits involved in time triggers, although they're quite high.

0

I have a solution for you :)

In reports you can subscribe to reports so they regularly run. So I created a generic apex class that you can use in the action. Install the code and then set up the report with your criteria and it can run daily (or whatever you like).

The apex will update a datetime field on your object (for example, ScheduleDateTime) - you specify this in the second column of the report.

When the datetime is updated your process builder can fire. Set the process builder criteria for is changed: ScheduleDateTime;

Let me know if that helps https://github.com/dthowell/DeclarativeScheduler

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.