I have below query to search for Existing Contact before creating new Contact in Salesforce. If there is a Contact with matching email and another Contact with matching Phone - results are not consistent- Sometimes it picks up with matching phone and sometimes with matching email.
How to make sure it always returns first Contact with matching email then with matching phone then by matching name and street? We have close to 450K Contacts.Will it effect Performance?
list<Contact> ExistingContact = [SELECT
id, firstname, lastname, email, Phone, MobilePhone, MailingStreet
FROM contact
WHERE (email=: con.Email AND email !='')
OR (Phone=:con.Phone AND Phone !='')
OR (MobilePhone=:con.Phone AND MobilePhone !='')
OR (firstname =:con.FirstName AND lastname =:con.LastName AND MailingStreet =:con.street)
LIMIT 1];