2

One of my sales reps accidentally uploaded Lead records list twice into the Salesforce prod environment. How can I delete duplicated records?

I've already used a query to find all records. The problem is that there are records like:

Company             Edit Date        Field / Event     First Name   Last Name
7 ELEVEN STORE #10104A  04/01/2017 18:30    Created.    7   ELEVEN
7 ELEVEN STORE #10104A  04/01/2017 18:28    Created.    7   ELEVEN
7-ELEVEN STORE #10110A  04/01/2017 18:28    Created.    7-ELEVEN    INC
7-ELEVEN STORE #10110A  04/01/2017 18:30    Created.    7-ELEVEN    INC
7 ELEVEN STORE #10120H  04/01/2017 18:28    Created.    7   ELEVEN
7 ELEVEN STORE #10120H  04/01/2017 18:30    Created.    7   ELEVEN
7-ELEVEN STORE #10146A  04/01/2017 18:30    Created.    7   ELEVEN
7-ELEVEN STORE #10146A  04/01/2017 18:28    Created.    7   ELEVEN
7-ELEVEN STORE #10147A  04/01/2017 18:28    Created.    7-ELEVEN    INC
7-ELEVEN STORE #10147A  04/01/2017 18:30    Created.    7-ELEVEN    INC

What criteria can I use in my query to get only the duplicated records?

4

You must have got a success file stored on your local machine after insertion of records. Take the last files from the two record insertion files and take the id's from them. Delete those id's via the data-loader.

|improve this answer|||||
  • 1
    Very good thought... does the Sales Rep have this result file? – Simon Lawrence Jan 5 '17 at 10:47
  • 1
    The person who has inserted the record will have that file on his system. In your case if 'Sales Rep' has inserted the records then he will for sure have the same. – Ruchi Jan 5 '17 at 10:50
4

I would recommend in an urgent scenario like this (and assuming you have the "power" to be so decisive) using the Developer Console to run some Anonymous Apex to draw out a list and delete the duplicate records

Dev Console

Looking at your data you can probably use the CreatedDate (and maybe the CreatedById field to narrow to the user) field to determine whether the leads were created at 18:28 or 18:30? Again, use the developer console Query Editor to tweek a query that gets the records and delete them

List<Lead> deadLeads = [SELECT CreatedDate, CreatedById FROM Lead WHERE CreatedDate = 2017-01-04T18:28:00.000+0000];
delete deadLeads;

I might also consider taking advantage of the Salesforce Matching Rules and Deduplication tools to either resolve this issue (by running them over existing data) and to stop the Sales Rep doing this again.

|improve this answer|||||
  • 3
    This query may delete other records also which may be created by other user at the same time. – Amit Chaudhary Jan 5 '17 at 11:00
  • I've tried to execute the following query: – sfdev Jan 5 '17 at 11:18
  • SELECT Name, Company, Address, Contact_Name__c, Status__c, OwnerId, CreatedById, CreatedDate FROM Lead where CreatedById = '0051400000C6n2f' AND CreatedDate = 2017-01-04T18:28:00.000+0000 – sfdev Jan 5 '17 at 11:18
  • In order to get only the records created during this time 2017-01-04T18:28:00.000+0000 but instead I received: "Sorry, no records returned." Could you please advise what else I need to add or exclude in the query to make it work and give me only the duplicated records? – sfdev Jan 5 '17 at 11:20
  • Replace the time stamp with the word YESTERDAY - and that should definitely load a tonne of records for that user, and then assert that the actual time stamp is 28 minutes and 0 seconds - which is probably unlikely (I would say a 1 in 60 chance!) you might have to tweek your query to use < and > operators to make a little window of a few seconds if the data load was slow. – Simon Lawrence Jan 5 '17 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.