+ Start a Discussion
System Administrator 874System Administrator 874 

Writing a query using SOQL to search for users using their first name and email

I am trying to write a query which will allow me to search for a user using their email and first name. I have it working mostly, however the issue I am facing is when a user has two or more words in their first name. 

For example - John Second Doe

Where they add John Second as their first name and Doe as their last name. 

I am using PHP to submit the request to Salesforce and then find the contact and assign their ID to our system. 

Select+Id+From+Contact+Where+Email='johndoe@lc.com'+AND+FirstName='John Second'

This is how the query looks so far, however this returns null. I assume this is because either its not supported or I am passing it in a wrong format. I have tried adding a + and %20, however niether work. I get an empty object.

I have confirmed that I have that user in my Salesforce system. (the name has been changed for the ticket).
Mohammed MohiddinMohammed Mohiddin
Hello,

Why have you written plus after each word in your query?
Try this query it worked for me.
Select Id  From Contact Where Email='johndoe@lc.com' And Firstname ='John Second'

If you still get null try refreshing or closing console and try again as records have not been updated.

Hope this helps.
System Administrator 874System Administrator 874
Yea, I think I need the + after each word in the query, because without that I get a null value returned. With the + the query works as expected and I get the result. However the only issue is that it does not work when there is a space in the first name. 

Would you be able to tell me how you were running the query? 


Based off the docs I believe we need the + as well. 
https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_query.htm
Mohammed MohiddinMohammed Mohiddin
This is what I have tried. I hope I have understood the question correctly.

PFA  Screenshot below
screenshot