1

I am having trouble with a new Validation rule because it is conflicting with Flow. I am getting this error:

Error Occurred: The flow tried to update these records: 0064V00001LmbdtQAB. This error occurred: FIELD_CUSTOM_VALIDATION_EXCEPTION: Closed Opportunities cannot be edited. Please create a new Opportunity.. You can look up ExceptionCode values in the SOAP API Developer Guide.

Salesforce Error ID: 2064168760-169264 (-617785307)

Need: We want to prevent the editing of Closed Opportunities except for certain users through a Validation Rule.

Problem: My validation rule seems to be conflicting with a flow we have that changed the Close Date to Today() when an Opportunity is Closed Won/Lost

Here is the formula for my Opportunity Validation Rule

AND(

PRIORVALUE(IsClosed)=True,

$User.Alias<>"bbond",

$User.Alias<>"cburn",

$User.Alias<>"igend",

$User.Alias<>"jgord"
)

Here is the criteria for the Opportunity Flow. It updated the Close Date to Today when an Opportunity is Closed:

1- Trigger when a Record is Created or Updated

2- Condition Requirements - Formula Evaluates to True

3- Formula: AND( ISCHANGED({!$Record.StageName}), {!$Record.IsClosed}=TRUE )

4- enter image description here

Does anyone know what I am doing wrong?

Thank you!

5
  • Though this isn't the source of your issues, I believe that custom permissions are generally recommended over using $User (and $Profile and $Role?). This official looking blog goes over setting it up and use in a validation rule.
    – Derek F
    Nov 29, 2022 at 23:47
  • Also, is this a before-save record-triggered flow, or an after-save record-triggered flow? Based on the Order of Execution, I'd think that an after-save flow would be liable to run into validation rules.
    – Derek F
    Nov 29, 2022 at 23:49
  • @DerekF - I edited my validation rule to go by profile, and I updated the flow to run before-save, and I'm still getting the same error. I don't know why because my Validation rule formula is bases on PRIORVALUE(IsClosed)=True. Thank you for your help Nov 30, 2022 at 0:05
  • Sanity check: That validation error text is verbatim your custom error text on that particular Validation Rule? And is that text only on that Validation Rule?
    – Moonpie
    Nov 30, 2022 at 2:22
  • @DerekF - Please disregard my last message. You were right. The answer actually was changing it to a before-save record-triggered flow. We actually had 2 flows that triggered from the Opportunity changing to closed. When I updated both to before-save record-triggered flows, it worked. Thank you! Nov 30, 2022 at 4:08

2 Answers 2

1

From my comment, the primary issue here is using an after-save record triggered flow (or flows) rather than a before-save record triggered flow.

tl;dr: If you're going to update a field on the record triggering the flow, use before-save flows.

Flow behavior

With an after-save flow, field updates cause the record to go through the "save procedure" again. This means that your validation rules are going to be evaluated again, and you're running into an issue when they are.

This is, as far as I've seen, the main difference between field updates on a workflow (which is being sunset), and field updates from an after-save flow. With workflow rules, the custom defined validation rules were not evaluated on the next run through the "save procedure".

So if validation rules are going to cause a problem, you should be using before-save flows (which are executed before validation rules are evaluated). Another benefit to using before-save flows is that they don't cause the record to go through an additional "save procedure" (saving cpu time, clock time, queries, query rows, dml rows, and dml statements).

The one gotcha

If your record triggered flow runs every time (no conditions to meet for the flow/field updates to run), then any change will attempt to update the close date.

This should trip your validation rule, but the error message your users get will probably be confusing. It could make them think that the flow is the problem, it could report the CloseDate field as the problem (even if your users were modifying a different field).

Good practice here would probably be to adjust your flow so it only fires when the Opportunity is changing to a closed won/lost state.

1
  • Thank you so much! This will work! Dec 2, 2022 at 2:04
0

Try adding the user for default workflow user (settings -> Process Automation Settings) into the validation rule bypass.

1
  • I have myself as the Default Workflow User but an still getting the error Nov 30, 2022 at 0:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .