0

When creating SOQL query with LIKE searching for a string, I do not get any answer or error. This is my code where I look for a string "John G."

$instance_url."/services/data/v45.0/query/?q=SELECT+Id,+First_Name__c,+Last_Name__c,+Lead__c,+HA_Review_Identifier__c+FROM+Reviews__c+WHERE+HA_Review_Identifier__c+LIKE+'%".$row['review_by']."%'";

API connection is working correctly since when I use below code it works well.

$instance_url."/services/data/v45.0/query/?q=SELECT+Id,+First_Name__c,+Last_Name__c,+Lead__c,+HA_Review_Identifier__c+FROM+Reviews__c+WHERE+HA_Review_Identifier__c+=+'".$row['review_by']."'";

It works only when $row['review_by'] is numeric in Salesforce and above query.

I read that I should use Parameterized Search like below:

$instance_url."/services/data/v45.0/parameterizedSearch/?q='".$row['review_by']."'&sobject=Reviews__c&Reviews__c.fields=Id,First_Name__c";

But this does not work.

Thanks

UPDATE: When I change in SF HA_Review_Identifier__c to numeric value and use first query without % then it works and I get result. So the % is the issue. Not sure how to encode it,

1 Answers1

-1

Correct query is:

$instance_url."/services/data/v45.0/query/?q=SELECT+Id,+First_Name__c,+Last_Name__c,+Lead__c,+HA_Review_Identifier__c+FROM+Reviews__c+WHERE+HA_Review_Identifier__c+LIKE+".urlencode("'%".$row['review_by']."%'")."";

PHP function urlencode() needs to be used, but only for the portion of the URL that has % character.

urlencode("'%".$row['review_by']."%'")

Hope it will help someone. Thanks for looking.