Usage of new ISCLONE() function in Record Triggered flows and Considerations
Overview
ISCLONE() is available in flows as part of Winter 23. So let us see a use case where we can use ISCLONE in flow and what are some considerations compared to the same implementation using Apex.
Use Case
The account is having 2 record types:
1. Standard
2. Premier
Both are assigned to different page layouts
In standard Account Layout, we have a new custom look-up added called Primary Contact, but it is not added to Premier Account Layout.
Since Clone is not available by default in Account - we need to create a custom clone button and add it to Premier Account Page layout:
Problem Statement
1. Create a new Standard Account by populating Primary Contact
2. Convert it to Premier Record Type
3. Clone the Account and create a new Account
4. Check the Premier Contact value in the new Account - Value is empty
Reason
Standard clone can only clone field values present in the UI. Since primary contact is not added to Premier Account it is not copied over to the new account.
How to Solve - Trigger
Since flow was not supporting an option to check if the new record is a cloned one, the traditional option is to use a trigger solution like shown below:
1. Check if the current record is a clone if so get the source id
2. Query the source Account to get primary contact and copy it over to the new Account
Since we have ISCLONE() available in Winter 23 - let us see how we can use this to solve the above problem:
How to Solve - Flow
We can create a record-triggered flow to solve this:
Step 1 - select an object and the trigger option
Step 2 - Add entry criteria
You can see ISCLONE() function is added as a criteria
Step 3 - Get Source ID
Unfortunately, flow is not supporting a mechanism to get the source id of the cloned record. So we need to use an apex action to get this value.
and call this from Flow:
Step 4 - Retrieve Primary contact
Step 5 - Update New Account with primary contact
The final Flow looks like below:
Considerations
1. Since we do not have a mechanism to fetch source id in flow we need to use apex to do that
2. Since apex actions are not supported in before flows - we need to use after insert flows to implement this
3. Since this is after flow - we need to execute an additional DML to update the primary contact. But in trigger, since this is before flow we can save one DML
Demo
Awesome article. loved it
ReplyDeleteProfessional Courses