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
Baron BortBaron Bort 

Query for existing records

I have a Salesforce environment deployed and it also contains data. I need to import some additional data into Accounts and Contacts, but I have reason to believe that the .csv that I need to use for the import contains records that already exist in Salesforce.

Let's assume that users have already made changes to some of the existing records, so I don't want to override any changes by using an Upsert.

I'm using Jitterbit to perform this insert operation. So far I've tried to grab a sample set of contact names from my .csv in my [SELECT Id, Name FROM Contact ...] query. The problem is that Jitterbit reports that no records are returned, when I know that some of the contact names do exist in Salesforce because I checked a few manually.

Jitterbit uses this particular query:
SELECT Id, Name FROM Contact WHERE Name like '%Person 1,Person 2,Person 3%'

 but it returns 0 results.

I tried:
... WHERE Name IN ('Person 1', 'Person 2', 'Person 3')

 but that returned 0 results as well.

Is there some way for me to check multiple Contact/Account names in a single query so I can confirm which records exist already or not? (My import files go into the 1000s)
Best Answer chosen by Baron Bort
James LoghryJames Loghry
Probably the most straight forward approach is to export your current Contact records into an Excel file, and then use Excel's VLOOKUP functionality to map matching contacts with their salesforce ids.  This is documented here: https://help.salesforce.com/servlet/servlet.FileDownload?file=01530000001x32RAAQ

O
therwise, you could create an external id field for your Contact record, then update the existing data to populate that external id (E.g. based on a unique criteria.. perhaps your contacts have unique email addresses or something), and then you could use the same external id criteria in your CSV file to perform an Upsert of the data.

To answer your query question though, this should work for a small subset of contacts, but once you go several contact names, it's going to get expensive..

SELECT Id, Name FROM Contact WHERE Name like '%Person 1%' Or Name like '%Person 2% Or Name like '%Person 3%';