Tell me more ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

As the title states, can you use LIKE in SQOL queries via the REST API?

Even with this basic query:

select Id from Account  where BillingState like 'VIC%' 

I'm getting an error back:

REST Response fault: [{"message":"SOQL statements cannot be empty or null","errorCode":"MALFORMED_QUERY"}]

Am I missing something obvious here?

share|improve this question
If you're still having problems post your code – superfell Aug 23 '12 at 2:00

2 Answers

up vote 13 down vote accepted

Yes you can. SOQL in the rest API supports all the same constructs that its SOAP older brother does. Remember to pass the SOQL as the 'q' parameter in the URL,and to URLEncode the soql when putting it in the query, e.g. https://na1.salesforce.com/services/data/v25.0/query?q=select+id+from+account

share|improve this answer
2  
Yup, just realised the problem was that I wasn't encoding the % sign. I'd actually tested encoding using what turns out to be a broken encoder online, it told me that % is just %, not %25! – LaceySnr Aug 23 '12 at 2:05
1  
Try using workbench.developerforce.com next time to formulate the SOQL query / REST request – DancinLlama Aug 23 '12 at 13:10

I think the issue is with the url encoding of the % in the like clause.

I just tried the following in the Workbench Rest API and it worked.

/services/data/v25.0/query?q=select+id+from+account+where+BillingState+like+'VIC%25'

share|improve this answer
Giving the accept to to @superfell because he got in there first, I just couldn't accept it within 10 minutes of asking it seems! – LaceySnr Aug 23 '12 at 2:10
Yes. Totally fair. I got distracted by my day job and when I turned back @superfell had the answer sorted. – Daniel Ballinger Aug 23 '12 at 2:12
@DanielBallinger hmm, day job - remind me what's that? – Saariko Aug 23 '12 at 7:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.