Check Duplicate Records Using Screen Flow in Salesforce

In Salesforce Flow, when we create a record using screen flow, we can check whether this record is already created and display the message for the same.

In this Salesforce tutorial, we are going to learn about Check Duplicate Records Using Screen Flow in Salesforce. We will create a screen flow to check whether the record we will create is already present. If the record is present, then display the error message.

What is the Duplicate Rule in Salesforce?

In Salesforce, a Duplicate Rule can block users from saving records that have been identified as possible duplicates or simply alert users that they may be creating a duplicate record but allow them to save the record anyway.

You can read the whole article on Different Ways to Prevent Duplicates in Salesforce.

How to Check Duplicate Records Using Screen Flow

Scenario:

While working as a Salesforce administrator, I was assigned a task to create a screen flow where we can apply duplicate rules to block users from creating duplicate Lead records and display the error message that the record you are creating already exists or is duplicated.

Using the above scenario and the following steps, we can check duplicate records using screen flow.

Create Screen Flow:

1. Click on the Setup -> Home Tab -> In Quick Find Box, Search for Flows. You will see an option under Process Automation -> Click on Flows.

  • Then, click on the New Flow button to create a new flow.
  • Here, we will use Screen Flow to create a duplicate record and check whether it displays an error message. To do that, create a flow with the Screen Flow component, click on it, and then click on the Create button.
See also  Auto-Assign Members to Account Team Using Salesforce Flow

Screen Element:

2. Now, we have to add a Screen to the Canvas. To do that, click on the Elements tab from the Toolbox. You will see the Screen element under the Interaction drag and drop screen component on Canvas.

  • Then, enter the Label and API Name into the Screen Component.
  • Now, we need to create some fields. Here, I have created the following fields that are required in the Lead object with the Label, and the API Name will automatically populate them.
  • Last Name, Email, Company, and Lead Status.
Checking Duplicate Records Using Screen Flow

Assignment Element:

3. To assign values to lead object fields, we need to fetch Leads object fields. For that, click on Add New Resource and enter the following details:

  • Resource Type: Variable.
  • API Name: var_Lead.
  • Data Type: Record( Because we are fetching Lead record fields).
  • Object: Lead.
Check Duplicate Records Using Screen Flow

4. Then, add an Assignment Element that will assign values created from the screen component to lead object fields. Enter the Label and API Name for the Assignment element.

  • In the section Set Variable Values, select the Resource(var_Lead) as a Variable that we created for the Lead Object. From that object, we can fetch lead object fields. Then, in the Value field, select the Screen Components that we created in the screen element.
Checking Duplicate Records Using Screen Flows

Gets Records Element:

5. We need to match the records we are creating with the records we already have in the Lead object. To do that, we need to add the Get Records element by clicking on the Plus ‘+ Add Element‘ icon. Enter a Label for it; the API Name will populate automatically.

How to Check Duplicate Records Using Screen Flow

Decision Element:

6. Then, we need to add a Decision Element to check whether the record we are creating is already present in the Lead Object. Enter the Label for the decision element. The API Name will populate automatically.

See also  How to Create a Related Record from a Salesforce Flow

Now add Yes and No as an Outcomes as follows:

  • Yes: If the record that we are creating is already present in the Lead Object, which we fetched from the Get Record element, then we will display an error message. We have to add a condition for that as follows:
  • Lead from Get_Leads_Records – Is Null – False.
  • No: If it does not match, then we will create a record for the same.
How to Check Duplicate Record Using Screen Flow

Screen Element:

7. If the condition gets True, that means the Yes Outcome will execute. At that time, we need to display an error message as ‘Duplicate Records’ using the Screen Element. For that, add a Screen Element and add an error message using the Display Text Component.

How to Check Duplicate Record Using Screen Flows

Create Records Element:

8. If the record that we create using a screen element does not match the lead object record, then No Outcome will execute, which means there will not be a duplicate record, and we can create this record. For that, add Create Record Element.

  • To do that, we need to add the Create Records element by clicking on the Plus ‘+ Add Element‘ icon. Enter a Label for it; the API Name will populate automatically.
  • Select ‘One‘ record to create at a time, and ‘use all values from that record‘ to set the record fields.
  • Then, in the Record field, select the Resource(var_Lead) that we created to assign the screen field value to the lead.
How Can Check Duplicate Records Using Screen Flow

Save, Debug, & Activate:

9. After setting up all labels and conditions, click the Save button to save the flow. For that, we need to enter the Flow Label. The API Name will automatically populate as we click the text box. The Description is optional; we can introduce our flow Shortly.

  • After Saving the flow, click on the Debug button. Then click on the Activate button; always remember to debug the flow before activating it. It’s good practice to use flow.
Check Duplicate Records Using Screen Flows

Conclusion

I hope you have an idea about the duplicate rule in Salesforce. We have seen how to check duplicate records using a screen flow in Salesforce. We have seen a screen flow to check whether the record we will create is already present. If the record is present, then display the error message.

See also  Create Record Trigger Flow in Salesforce | What is Record Trigger Flow in Salesforce

You may like to read: