You need to sign in to do that
Don't have an account?
benwalk
How to query contact with apostrophe in SOQL using REST?
It's the same question as https://developer.salesforce.com/forums/?id=906F0000000MMbqIAG, but with a twist: I need to do this via REST.
For example, the REST API documentation uses the following example:
What should the query parameter look like for the following SOQL?
Using this format returns:
'No viable alternative at character \"'
Using "john.o\'connor@skynet.com" returns:
'Bind variables only allowed in Apex code'
So does URI encoding the backslash to %5C (john.o%5C'connor@skynet.com).
I am stuck. Can anyone help?
For example, the REST API documentation uses the following example:
curl https://yourInstance.salesforce.com/services/data/v20.0/query/?q=SELECT+name+from+Account -H "Authorization: Bearer token"but my SOQL uses email address to lookup a Contact. And this email happens to contain an apostrophe.
What should the query parameter look like for the following SOQL?
SELECT+Id,+Email,+Name,+Phone+FROM+Contact+WHERE+Email=john.o'connor@skynet.com+AND+AccountId='001W010000HnaZhiAJ'
Using this format returns:
'No viable alternative at character \"'
Using "john.o\'connor@skynet.com" returns:
'Bind variables only allowed in Apex code'
So does URI encoding the backslash to %5C (john.o%5C'connor@skynet.com).
I am stuck. Can anyone help?
All Answers
you can use 2 ways to escape characters in you SOQL Query Via RestAPI call
Way1:
StringEmail='john.o\'connor@skynet.com';
StringEmail= StringEmail.replace('\'','%27');
Or use can use:
StrQuert=StrQuert.replace('\'','%27');
Way2:
you can Use Encoding and Decoding Concept:
String stringToEncode = ''john.o'connor@skynet.com';
String encodedUrl = EncodingUtil.urlEncode(stringToEncode, 'UTF-8');
System.debug(encodedUrl);
Hope This will help you.
Thanks
karthik
I've tried the following values for <SOQL> (in the above template):
ALL of these return:
I've also tried all of the above variations while wrapping the email address in double quotes. No luck.