The PRE function in Expression Builder returns the previous value of the specified field when the field value is modified but before the value is updated in the database.
CAUTION: It is strongly recommended that you do not use the PRE function with workflow rules containing a Wait action, because the Wait action affects the PRE function. Any actions following the Wait action are not performed until the specified wait period has expired. The remaining actions are performed in a different batch operation than the operation where the rule was originally triggered, and the values of the fields on the record prior to the action that triggered the workflow rule are not preserved. Therefore, the previous value and the current value of the field are always considered to be the same.
The following table describes the arguments for the function.
The name of the field that was modified.
The following considerations apply when using the PRE function:
- In conditional expressions, such as workflow conditions and validation statements, when you use the PRE function to retrieve the previous value of a field, remember that the initial value of the field can be blank (that is, a null value). If the initial value is null, any comparison with a non-null value results in unpredictable behavior. To ensure that conditional expressions are evaluated correctly in such cases, use the PRE function with the IfNull function as shown in this example:
IfNull([<FieldName>], "Invalid") <> IfNull(PRE('<FieldName>'), "Invalid")
In this example, the text string Invalid is used to replace the null value, but you can use any string that you want, provided that the string does not exist as a value in the field that is being examined.
- If the PRE function is used in a workflow rule or action that is invoked after a Wait action, the function does not return the previous value of a field. However, you might have a business process that requires such comparisons. In such cases, you can use a workflow rule with the Before Modified Record Saved trigger event to store the previous value of a field in any unused field on the record type. You can then use the stored field value for any comparisons you require in workflow rules that have the Wait action.
When you create the workflow rule to store the previous value of a field in an unused field on the record type, remember that the previous value of the original field might be blank (that is, a null value). Therefore, you must use an expression such as the following to store a default value if a null value is encountered:
In this example, the text string Invalid is the default value that is used to replace a null value, but you can use any string you want, provided that the string does not exist as a value in the original field.
Example of Creating a Workflow Rule That Sends an Email to the Previous Owner of an Account Record
The following is an example of how to create a workflow rule that sends an email to the previous owner of an account record when the owner of the record is changed.
To create a workflow rule that sends an email to the previous owner of an account record
- Create a workflow rule for the Account record type with the When Modified Record Saved trigger event.
- Save the workflow rule.
- Create an Add an Email action on the workflow rule.
- On the workflow action, do the following:
- In the To field, select Specific Email Address.
- In the To field expression text box, add the following expression:
JoinFieldValue('<User>', IfNull(PRE('<OwnerId>'), "email@example.com"),'<EMailAddr>')
- Add the necessary text in the subject and body of the email.
- Save the workflow action.
See the following topics for related Expression Builder information: