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:
Thanks, looking forward to some responses.
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 : https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_query.htm