function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MilanMilan 

Best Design Practice : Checking for existing leads

Hello,
 
In our application, we need to verify if a lead already exists, before we insert (create) a new one. One of the ways we are going to check for existing leads is based on email. i.e If a Lead with a certain email id already exists, it means it need not be inserted (created) again.
 
Now, we may have to insert thousands of leads at a time. Which in turn means verifying all those thousands of leads before we insert them. What is the best possible approach, keeping time in mind, to do this ? Note : Time is critical !
 
One approach that immediately comes to my mind is using a Query in Partner WSDL and passing a batch of say n email Ids at a time. i.e:
 
 qr = stub.query("select email, FirstName, LastName, Id from Contact where email IN ('abc@asd.com', 'werr@dfdf.com' ,'cxvcv@uoa.edu','dfdf.fd@wer.com', 'fd@abc.com' ,...........)");    
   
  1. Would this be a good idea ?
  2. It is never a great idea to fire a 'like' query in existing production database... so do I have a better option ?
  3. Firing a single call for each lead certainly seems a slower option ... isnt it ?

Thus can anyone suggest what is the best practice for such a scenario ?

Thanks,

Milan

MilanMilan

Any inputs for me ?All help appreciated!

Thanks,

Milan

sfdcfoxsfdcfox
I would recommend using upsert. It allows you to specify a field to match against, and update the record if it exists, or create the record if it doesn't. Upsert returns an array (like the other calls) that tells you if the record was successfully created or updated (or, if multiple duplicates exist). The only limitation here is that you can only use one field, but the upside is that Salesforce handles all the logic for you. If you need multiple fields, then you would need to run a query on a number of records. Using "IN" should be no worse than using field = 'value' or field = 'value' syntax.

~ sfdcfox ~

SaurabhRawaneSaurabhRawane
One possible solution if you have your duplication logic around only one field that is the email for the lead would be to have a Validation Rule written around email field,so that if any record exits inside SFDC with the same email address we will prevent new record with the same email to enter,we track the not inserted records using the SaveResult Object...

Hope i understood your problem and provided a gud solution  ^_^