Last Updated on April 18, 2022 by Rakesh Gupta
Big Idea or Enduring Question:
- How do you resolve the FIELD_INTEGRITY_EXCEPTION error?
The Record-Triggered Flow is a way of automating business processes. Record-Triggered Flow is a powerful tool for system administrators and developers to implement business processes without writing code. However, with great power comes great responsibility – If a user starts creating a new flow for each requirement – or creating flows without understanding Salesforce limitations – then, a user may encounter many issues, either in the future or, while the testing/deployment phase.
In my last post How to Fix FIELD_CUSTOM_VALIDATION_EXCEPTION Error, I discussed how to solve the FIELD_CUSTOM_VALIDATION_
This article goes one step further; it explains another common error – FIELD_INTEGRITY_EXCEPTION Error. The article will help you to understand the following items:
- Why errors could occur
- How to identify errors by reading system-generated flow error email
- How to solve the problem.
Business Use case
Tamara McCleary is working as a System Administrator at Gurukul on Cloud (GoC). GoC implemented case management a year ago. Tamara has a requirement from her manager that, as soon as a case is closed, assigns related cases to the parent case owner.
What is FIELD_INTEGRITY_EXCEPTION Error?
A user mostly encounters a FIELD_INTEGRITY_EXCEPTION error when he populates a lookup field with the wrong Id.
For example, while creating a contact via flow if, in the place of AccountId, a user passes an Opportunity record id, then, the user will encounter a FIELD_INTEGRITY_EXCEPTION error.
Below, I will show you how to avoid getting a FIELD_INTEGRITY_EXCEPTION Error while using the Salesforce Flow.
First, I will update child cases by passing the wrong ID (maybe an account Id).
This will generate a FIELD_INTEGRITY_EXCEPTION error because you are only allowed to pass valid User or QueueID for a case owner.
Next, I will show you how to identify the root cause behind the FIELD_INTEGRITY_EXCEPTION error followed by a way to solve it.
Create a Flow that Generates a FIELD_INTEGRITY_EXCEPTION Error
To solve this requirement, we will use the After-save Record-Triggered Flow. Check out this article to understand why we are using after-save record-triggered flow for this scenario.
There are 3 steps to solve Tamara’s business requirement using After-Save Record-Triggered Flow. We must:
Step 1: Define Flow Properties
- Click Setup.
- In the Quick Find box, type Flows.
- Select Flows then click on the New Flow.
- Select the Record-Triggered Flowoption, click on Create and configure the flow as follows:
- Object: Case
- Trigger the Flow When: A record is created
- Set Entry Criteria
- Condition Requirements: None
- Optimize the Flow For Action and Related Records
- Click Done.
Step 2: Using Decision Element to Check the Case Status
Now, will use the Decision element to check if the case is closed or not.
- On Flow Designer, click on the+icon and select the Decision element.
- Enter a name in the Label field; the API Name will auto-populate.
- Under Outcome Details, enter the Label the API Name will auto-populate.
- Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
- Row 1:
- Resource:{!$Record.IsClosed}
- Operator: Is Null
- Value: {!$GlobalConstant.True}
- Row 1:
- When to Execute Outcome: Only if the record that triggered the flow to run is updated to meet the condition requirements
- Click Done.
Step 3: Add Action – Update Records
The next step is to update the owner of child cases, for this, we will use the Update Records element.
- On Flow Designer, below the Closed node, click on the +icon and select the Update Records element.
- Enter a name in the Label field; the API Name will auto-populate.
- For How to Find Records to Update and Set Their Values select Specify conditions to identify records, and set fields individually
- Object: Case
- Select All Conditions Are Met (AND).
- Set Filter Conditions
- Row 1:
- Field: ParentId
- Operator: Equals
- Value: {!$Record.Id}
- Row 1:
- Set Field Values for the Opportunity Records
- Row 1:
- Field: OwnerId
- Value: {!$Record.AccountId}
- Row 1:
- Click Done.
In the end, Tamara’s Flow will look like the following screenshot:
Once everything looks good, perform the steps below:
- Click Save.
- Enter Flow Label the API Name will auto-populate.
- Click Show Advanced.
- API Version for Running the Flow: 55
- Interview Label: Update Child Case Owner {!$Flow.CurrentDateTime}
- Click Save.
Almost there! Once everything looks good, click the Activate button.
Proof of Concept
- Update a case record to closed, which has at least one child case.
- Once you’re done, click on the Save button. Boooommmm, you encounter a FIELD_INTEGRITY_EXCEPTION error, as shown in the following screenshot:
👉 As mentioned earlier, the reason behind the error is, that we are wrongly updating Case record ownership to an accountId.
Fix FIELD_INTEGRITY_EXCEPTION Error
To fix the FIELD_INTEGRITY_EXCEPTION error in a Flow, you have to pass the correct Id for a lookup field. let’s modify the flow to pass the right value to the OwnerId field.
Step 1: Clone Existing Flow
- Click Setup.
- In the Quick Find box, type Flows.
- Select Flows then click on the Flow Name that will be modified. In this case Update Child Case Owner.
- Click on the Save As button at the top right of the Flow builder.
- Click Save.
Step 2: Modify Update Records Element
- On Flow Designer, Edit the Update Child Cases element to modify the OwnerId mapping.
- Set Field Values for the Opportunity Records
- Row 1:
- Field: OwnerId
- Value: {!$Record.OwnerId}
- Row 1:
- Click Done.
Formative Assessment:
I want to hear from you!
What is one thing you learned from this post? How do you envision applying this new knowledge in the real world? Feel free to share in the comments below.
Would this apply to the “FIELD_CUSTOM_VALIDATION_EXCEPTION” error as well? If not, do you have a blog post about that coming out soon? 🙂
For FIELD_CUSTOM_VALIDATION_EXCEPTION check this article
https://automationchampion.com/2022/04/17/how-to-fix-field_custom_validation_exception-error-2/