Skip to main content

Avoid Duplicate Records Using Flow

In this blog post lets see how to avoid duplicate records in Salesforce using the powerful feature – Flow, As the word says, flow easily flows to fulfill the requirements with ease.  Many think of appexchange solutions and source code to avoid the duplicate record in salesforce, But the method I'm going to explain here is completely different and very simple. It helps you to reduce your code and can easily rebuild for other objects with different field logic with simple clicks.

Lets jump into the solution, we will use flow to check duplicate record logic and use apex trigger to initiate the Flow whenever a record is created or updated.

Visual WorkFlow:[Click]

First we will create the Flow to check the duplicate records based on the name and store the result in the variable. In this example, we will use the Account object for the dupe check.

Step 1 : Create a new visual flow with the Name ‘DuplicateAccountCheck'
Step 2 : Click and drag the RecordLookup into the flow window and Name it as ‘DuplicateCheck'
Step 3 : Select the object as ‘Account'
Step 4: In the Fields select “ID" and condition as "does not equal” in the value and create new variable ‘varAccountId’.
Step 5: Select Field as “Name” and Operator as “equal” in the value and create new variable ‘varAccountName'.

Note: Set Variable Input/Output Type as InputOnly

Step 6: Select the field as ‘Name’ and under the variable create new variable ‘varReturnAccount'.
Step 7: Select the check box Assign null value to the variable if no records are found and save it.

Whenever this flow is initiated with the parameter Account name and Id then it will check for the Acoount record based on the name, if any record matches then it will store in the variable ‘varReturnAccount’. So now logic to check duplicate account record is ready, lets move on to the next logic.


We easily covered the major logic for duplicate check without writing a single line of code using flow, all we going to do now is call our flow whenever a record is created or updated from trigger and display error message if it has duplicate record. Calling flow in an apex class is straight forward approach, below is the apex trigger code which will call your flow

Whenever a new record is inserted or updated, the trigger will call the flow which will perform the duplicate check and store it in the variable, if the variable is not null then it will throw the error message for that particular record. Now we linked the flow and trigger, which helps non-developers to build solutions for the complex problem with the more Clicks and less Code.

Where you can Learn more about Flow?
There are bunch of documents and blogs post available online, but I'm going to recommended the Trailhead module, following are the top 3 reasons for that
1. You will have all resource in one link[Video, demo, other related references link]. One stop to learn everything
2. You will have an interesting challenge at the end to test your knowledge
3. The best thing is you will earn BADGES and POINTS which will be added in your community profile.

Its really powerful feature in salesforce platform where you can able to reduce lots of visualforce and apex code in the org and the another cool things is you can able to automatically trigger the flow from the Lightning Process builder and Trigger.

Now its your turn to learn about Flow and share your use case in the comment section where you reduced the code using Flow. Start exploring more aboutSalesforce Trailhead module.


  1. Hi Karanraj,

    I created a Process Builder process that automatically adds a Staff Contact record to our Bi-Weekly newsletter Campaign. Since Staff Contact records are only created on the hire date there is no worries about duplicate records in the campaign. But, I'd like to use this process for other auto contact to campaign scenarios, but then will have duplicate issues. I would to use your approach to Flow to preclude dupes, but I am unsure as to where and how to install the Apex trigger. Could you offer some guidance in that area, and I assume some of that code would change since its pointing to the Account record. Thanks in advance for any help with this.



  2. Thank you, this blog is awesome and super. I really love your article. Thanks once again,
    Dubai VPS Hosting


Post a Comment

Popular posts from this blog

Export records from List view – ListView API

As part of the Winter’15 release salesforce introduced the List View API features which helps us to get details and records of list views for an object. I was started exploring more about the List view API and trying to build an use case using that. So I searched about List View in the IdeaExchange site then found that many users are looking for a solution to export records to excel directly from the list view. I built a solution for that Idea, which helps user to download all the records directly from the List view for both standard and custom object. You don’t have to make any change in the code to use this functionality for different objects. All you need is to create a custom button for that object as mentioned below. Lets take an example for Account object 1. Go to Setup –> Accounts –> Buttons, Links and Actions 2. Click ‘New Button or Link' 3. Enter  Label, Name and select display type as ‘List Button’ 4. Content source as “Onclick Javascript” and paste the

Lightning Picklist Path Component

Create your custom path for picklist field in any standard and custom objects. The new lightning picklistpath component in Winter18 helps us to display the picklist field progress similar to the lightning path. The path is rendered as a horizontal bar with one chevron for each picklist item, this component doesn't have key fields or guidance information and doesn't display the mark complete button similar to the lightning path.  <lightning:picklistPath aura:id="picklistPath" recordId="{!v.recordId}" picklistFieldApiName="status" / > The picklist path will display the progress based on the recordId and picklistApiName attribute value. Specify the API name of the picklist field in the picklistAPIName attribute which you want to display in the page layout and specify the Salesforce record ID in the recordID attribute so it renders the current value for the field in the page.   In this example, the status field in the case object disp