Search code examples
salesforcesoql

SOQL query for getting contacts and leads by email


I'm trying to write a single soql query to get all contacts and leads with a particular email. Now, I'm able to write two different queries to search for contacts and leads. But is this possible using a single query(to search on multiple objects).

The reason I'm looking for a single query is that, I'm using salesforce REST API in javascript and I don't want two separate requests for contact and lead search.


Solution

  • Thanks Adam. This definitely is a way to go. But I just tried SOSL instead of SOQL and the workbench.developerforce.com helped me great deal to try out my queries.. I was able to fire a simple SOSL query to search in both Lead and Contact objects. The query is

    FIND {[email protected]} IN EMAIL FIELDS RETURNING Contact, Lead