Skip to main content

Hi Salesforce Fam, 

 

For the Contacts upload, is there a way to perform duplicate checking using a script in Data Inspector before loading the records 

 

Currently, bulk uploads appear to bypass the existing business rules and create new Contact records. 

 

Is there a way, I would be able to run a query to identify potential duplicate Contacts before the upload. The main duplicate check would be based on email, and potentially First Name + Last Name where Email is blank.

4 answers
  1. Today, 9:26 AM

    Hi @Madhu Mithraa Prabakar

     

    Data Inspector can run SOQL against existing org data, but it can't compare against your upload file directly (that file isn't in the org yet). So the dedup check happens in two parts:

    existing-duplicates-in-org (SOQL) and incoming-file-vs-org

    (needs a bit more than a single query).  

     

    Here's the practical approach: 

    1. Find existing duplicates already in the org (run in Data Inspector or Query Editor) 

    By Email: 

    SELECT Email, COUNT(Id) recCount

    FROM Contact

    WHERE Email != null

    GROUP BY Email

    HAVING COUNT(Id) > 1

     

    By First + Last Name where Email is blank:

     

     

    SELECT FirstName, LastName, COUNT(Id) recCount

    FROM Contact

    WHERE Email = null

    GROUP BY FirstName, LastName

    HAVING COUNT(Id) > 1

     

    2. Check your incoming file against the org

    before

    loading 

      

    Data Inspector can't diff a CSV against Salesforce data, so pick one: 

     

    • Fast/manual: Export all existing Contact Email (and FirstName/LastName where Email is blank) to CSV, then VLOOKUP/COUNTIF your load file against that export in Excel before running Data Loader. Good for a one-off load.
    • Repeatable/scripted: Load the file into a staging custom object (or Data Loader's own "Export" + a quick script), then run an Apex script (Execute Anonymous or a one-time class) that queries existing Contacts by Email/Name and flags matches before you actually insert. Better if this upload happens regularly.
    • Native, ongoing fix: If Email is genuinely unique per Contact, consider marking it External ID / Unique and using Upsert (keyed on Email) instead of Insert Salesforce will then match/update instead of creating duplicates on every future load, not just this one.

    Root cause worth checking 

      

    Bulk/API loads bypassing your existing dedup logic is usually because the

    Duplicate Rule's matching rule isn't scoped to cover API-based inserts

    , or the rule action is "Report" (allow + log) rather than "Block." Worth confirming in Setup → Duplicate Rules whether the Contact matching rule you already have is actually configured to fire for this load method if it isn't, fixing that prevents this for every future bulk load, not just this one. 

     

    I hope you find the above information helpful. If it does, please mark it as Best Answer to help others too.

0/9000