0

I want to bind variable in get request, but it gives me error "Bind variables only allowed in Apex code","errorCode":"MALFORMED_QUERY"}". How to do it?

Account account  =  new Account(name = 'test');
request.setEndpoint('https://login.salesforce.com/services/data/v52.0/query/' +
                '?q=SELECT+Id+FROM+Account+WHERE+name=:account.name');
2
  • What are you actually trying to accomplish here? There's no need to callout to query your own org, and that Account has no Id because you didn't insert it. Please edit to provide context and clarity.
    – David Reed
    Commented Aug 18, 2021 at 15:44
  • @DavidReed i am calling to another org. Account var i wrote just for here example, cause there are many code.
    – Solmetirka
    Commented Aug 18, 2021 at 15:47

1 Answer 1

0

You need to put the value directly in to the query string:

request.setEndpoint('https://login.salesforce.com/services/data/v52.0/query/' +
            '?q=SELECT+Id+FROM+Account+WHERE+name=\''+EncodingUtil.urlEncode(String.escapeSingleQuotes(account.name))+'\'');

You cannot bind to the variable in a callout, because it has to be interpolated directly into the string. This is a limitation of how HTTP callouts work in general.

1
  • got it, thanks.Seems good.
    – Solmetirka
    Commented Aug 18, 2021 at 15:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .