SOQL Query Like Operator not returning results

I have ran into what seems to be a SOQL issue in either: query syntax or I've discovered a bug. I state that this might be a either a query syntax issue or a bug based on the premise that I've searched for clues and I've found nothing.

Anyways, I have created a custom view. This custom view is titled "Leads Test Cadinal". In this, I have added only 1 contact. I've populated the company field with "Cadinal Inc".

Now what I'm trying to do is fetch that contact with the company name "Cadinal Inc" (for that particular view obviously). When I execute the SOQL I get no hits returned from Salesforce despite the contact existing in the list.

Now onto the more techincal details:

I invoke the describe query in order to find the query that I want to execute to get that particular contact out. This is the query I receive after invoking the describe call

SELECT Name, Company, State, Email, toLabel(Status), CreatedDate, Owner.Alias, IsUnreadByOwner, Id, LastModifiedDate, SystemModstamp, Owner.Id, OwnerId FROM Lead WHERE IsConverted = false AND Company like '%Cadinal%' ORDER BY Name ASC NULLS FIRST, Id ASC NULLS FIRST 

When I receive the query from the describe call, the query that I will use to fetch the contact in the list is the following:

/services/data/v38.0/query?q=SELECT id , email, Company FROM Lead WHERE IsConverted = false AND Company like '%Cadinal%' ORDER BY Name ASC NULLS FIRST, Id ASC NULLS FIRST

Now what I am confused in is why the query fails to fetch the record? My hypothesis is that Salesforce keeps

%Ca% 

As a reserved word. I do not know why this query fails, can someone point me in the right direction on how to correctly query this.

The following is a screen shot of my sample lead:

Leads View

Thanks, looking forward to some responses.

3

1 Answer

Please URL Encode the SOQL Query before making the REST call. Something like below should work :

/services/data/v38.0/query?q=SELECT+id+%2C+email%2C+Company+FROM+Lead+WHERE+IsConverted+%3D+false+AND+Company+like+%27%25Cadinal%25%27+ORDER+BY+Name+ASC+NULLS+FIRST%2C+Id+ASC+NULLS+FIRST

Reference :

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like