Record Triggered Flow- Summer’20 Salesforce Release Feature
n
Requirement:nI have a business use case where I need to restrict users from entering duplicate child records for the same parent record.
n
Logic:
- n
- I decided to create one unique text field on the child object and then update it with a unique key value.
- As the field marked as unique if a duplicate record comes with the same key then the system will throw an error message.
n
n
Solution Spectrum:nI had various options on hand to achieve this but I found the record triggered flow is the best option.n
Option 1: Formula Field + Using Duplicate and matching rule
n
Option 2: Text Field + Workflow Field Update + Duplicate and matching rule
n
Option 3: Text field + Process Builder
n
Option 4: Before Event Apex Trigger
n
Option 5: Before Event, Record Triggered Flow (Summer’20 Release)
Option 1: Formula Field + Using Duplicate and matching rule
Steps:
- n
- I created a formula field on the child object to populate (Parent.Id+CurrentRecord.State) Because I wanted unique records by State.
- Then I tried to use this field in the Matching rule to find duplicates, but it’s not available there because of the formula field.
n
n
Outcome:
- n
- This Solution didn’t work.n
n
Option 2: Text Field + Workflow Field Update + Duplicate and matching rulen
Steps:n
- n
- Create a Text field instead of a formula field.
- Update field with unique key value using a workflow field update on the child object.
- Create duplicate and matching rules to show an error message.
n
n
n
Pros:n
- n
- Easy to configure
- User-friendly error message on duplication
n
n
Cons:n
- n
- Performance issue — Rules on child records, will execute for all records under the parent.
- Workflows are executed very late in the execution context
- Same object update is there hence recursion must be handled.
- Because of this update if there are any other workflows or process builders or triggers are there on the same object then those will be executed.
n
n
n
n
Outcome:n
- n
- Works but not recommended, due to poor performance.
n
n
Option 3: Text field (Mark it as Unique) + Process Buildern
Steps:n
- n
- Create a Text field marked as unique.
- Update field with unique key value using a Process builder action field update on the child object.
n
n
Pros:n
- n
- Easy to configure
- The unique field will handle to display the error
n
n
Cons:n
- n
- Performance issue — Process Builder
- Same object update is there hence recursion must be handled.
- Because of this update if there are any other workflows or process builders or triggers are there on the same object then those will be executed.
n
n
n
Outcome:n
- n
- Works but not recommended, due to poor performance.
n
Option 4: Before Event Apex Triggern
Steps:n
- n
- Write before insert/update event trigger
- throw error from trigger using .addError() standard method.
n
n
Pros:n
- n
- Easy to build
- Before the event trigger, it is, hence no need to make any DML
- No need to worry about recursion
n
n
n
Cons:n
- n
- Test class and Code coverage is required
n
Outcome:n
- n
- This solution works but a better solution is available 🙂
n
n
Option 5: Before Event, Record Triggered Flow (Summer’20 Release)
n
Steps:
- n
- Create a Text field mark it as Unique.
- Update field with unique key value using a flow (Before Save Record Triggered)
- The system will throw an error preventing duplication.
n
n
n
Pros:
- n
- Easy to configure
- Faster performance
- No need to worry about recursion
- Doesn’t fire any other workflow, process builder or triggers
n
n
n
n
Cons:
- n
- Not really if you are comfortable building a flow.
n
Outcome:
- n
- Works very well.
n
Thank you for reading my post, please share your thoughts and comments.