10

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?

  • If you're still having problems post your code – superfell Aug 23 '12 at 2:00
21

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

  • 3
    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! – Matt Lacey Aug 23 '12 at 2:05
  • 2
    Try using workbench.developerforce.com next time to formulate the SOQL query / REST request – James Loghry Aug 23 '12 at 13:10
17

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'
  • 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! – Matt Lacey 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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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