Skip to main content
replaced http://salesforce.stackexchange.com/ with https://salesforce.stackexchange.com/
Source Link

** significantly updated my answer as it contained a wrong assumption **

Validation rules will not run after a field update (credits to Amit. See his answer for a full explanation).

So you have to do the validations before scheduling the update. Do note that on every new update of the record, the workflow rules are evaluated again and if the conditions are no longer met, the scheduled field update is revoked. So theoretically the update will then never happen if the record does not meet the conditions. However, this is not valid if the conditions consist of data on related records.

Validations in apex triggers WILL run after a field update, so they will block the update and leave the record unchanged. In this case you can also build in a notification mechanism that the update failed, e.g. send out an email or insert a record into a logging table.

All in all the safest way to do this would be via an apex trigger, including a notification mechanism.

FYI some earlier discussion on this subject here: Bests practices for handling potential errors as a result of time based workflowBests practices for handling potential errors as a result of time based workflow

** significantly updated my answer as it contained a wrong assumption **

Validation rules will not run after a field update (credits to Amit. See his answer for a full explanation).

So you have to do the validations before scheduling the update. Do note that on every new update of the record, the workflow rules are evaluated again and if the conditions are no longer met, the scheduled field update is revoked. So theoretically the update will then never happen if the record does not meet the conditions. However, this is not valid if the conditions consist of data on related records.

Validations in apex triggers WILL run after a field update, so they will block the update and leave the record unchanged. In this case you can also build in a notification mechanism that the update failed, e.g. send out an email or insert a record into a logging table.

All in all the safest way to do this would be via an apex trigger, including a notification mechanism.

FYI some earlier discussion on this subject here: Bests practices for handling potential errors as a result of time based workflow

** significantly updated my answer as it contained a wrong assumption **

Validation rules will not run after a field update (credits to Amit. See his answer for a full explanation).

So you have to do the validations before scheduling the update. Do note that on every new update of the record, the workflow rules are evaluated again and if the conditions are no longer met, the scheduled field update is revoked. So theoretically the update will then never happen if the record does not meet the conditions. However, this is not valid if the conditions consist of data on related records.

Validations in apex triggers WILL run after a field update, so they will block the update and leave the record unchanged. In this case you can also build in a notification mechanism that the update failed, e.g. send out an email or insert a record into a logging table.

All in all the safest way to do this would be via an apex trigger, including a notification mechanism.

FYI some earlier discussion on this subject here: Bests practices for handling potential errors as a result of time based workflow

added 263 characters in body
Source Link
Guy Clairbois
  • 10.7k
  • 32
  • 54

The record** significantly updated my answer as it contained a wrong assumption **

Validation rules will not be edited if there is an errorrun after a field update (either validation rule or triggercredits to Amit. See his answer for a full explanation).

There is no waySo you have to handle a time-baseddo the validations before scheduling the update. Do note that on every new update of the record, the workflow rules are evaluated again and if the conditions are no longer met, the scheduled field update failure currentlyis revoked.

  So theoretically the update will then never happen if you want feedback on the failure ofrecord does not meet the updateconditions. However, I see only 2 options:this is not valid if the conditions consist of data on related records.

  1. create a report that you run periodically to check for records that have an invalid status
  2. do critical updates via apex triggers, which do allow you to catch and process failed updates

WRT 2Validations in apex triggers WILL run after a field update, you could either useso they will block the time-based workflow to schedule an update toand leave the record (only updating a non-validated field) and then baseunchanged. In this case you can also build in a trigger onnotification mechanism that to do the actual update failed, or use a batch job (ee.g. nightly) to identify and updatesend out an email or insert a record into a logging table.

All in all the relevant recordssafest way to do this would be via an apex trigger, including a notification mechanism.

FYI some earlier discussion on this subject here: Bests practices for handling potential errors as a result of time based workflow

The record will not be edited if there is an error (either validation rule or trigger).

There is no way to handle a time-based workflow field update failure currently.

  So if you want feedback on the failure of the update, I see only 2 options:

  1. create a report that you run periodically to check for records that have an invalid status
  2. do critical updates via apex triggers, which do allow you to catch and process failed updates

WRT 2, you could either use the time-based workflow to schedule an update to the record (only updating a non-validated field) and then base a trigger on that to do the actual update, or use a batch job (e.g. nightly) to identify and update the relevant records.

FYI some earlier discussion on this subject here: Bests practices for handling potential errors as a result of time based workflow

** significantly updated my answer as it contained a wrong assumption **

Validation rules will not run after a field update (credits to Amit. See his answer for a full explanation).

So you have to do the validations before scheduling the update. Do note that on every new update of the record, the workflow rules are evaluated again and if the conditions are no longer met, the scheduled field update is revoked. So theoretically the update will then never happen if the record does not meet the conditions. However, this is not valid if the conditions consist of data on related records.

Validations in apex triggers WILL run after a field update, so they will block the update and leave the record unchanged. In this case you can also build in a notification mechanism that the update failed, e.g. send out an email or insert a record into a logging table.

All in all the safest way to do this would be via an apex trigger, including a notification mechanism.

FYI some earlier discussion on this subject here: Bests practices for handling potential errors as a result of time based workflow

Source Link
Guy Clairbois
  • 10.7k
  • 32
  • 54

The record will not be edited if there is an error (either validation rule or trigger).

There is no way to handle a time-based workflow field update failure currently.

So if you want feedback on the failure of the update, I see only 2 options:

  1. create a report that you run periodically to check for records that have an invalid status
  2. do critical updates via apex triggers, which do allow you to catch and process failed updates

WRT 2, you could either use the time-based workflow to schedule an update to the record (only updating a non-validated field) and then base a trigger on that to do the actual update, or use a batch job (e.g. nightly) to identify and update the relevant records.

FYI some earlier discussion on this subject here: Bests practices for handling potential errors as a result of time based workflow