while running this code in anonymous window getting the error below

        String useremailaddress = '[email protected]';
        HttpRequest req = new HttpRequest();
        String query='SELECT+id+,+uuid__c+from+User+WHERE+Username='+useremailaddress;
        Http http = new Http();
        HTTPResponse resp = http.send(req);

Getting error malformed on where clause

[{"message":"\nuuid__c from User where Username= '[email protected]'\n
^\nERROR at Row:1:Column:53\nBind variables only allowed in Apex code","errorCode":"MALFORMED_QUERY"}

1 Answer 1


As the error says you cannot use a Bind Variable in SOQL via REST API.

Try modifying the code as below

String query= = 'SELECT+id+,+uuid__c+from+User+WHERE+Username=\'' + String.escapeSingleQuotes(useremailaddress)+ '\'');


What I have done is instead of using the bind variable there, made sure to pass it as a normal string. I have used '\'' to escape the quotes. Also enclosed your username in escapeSingleQuotes to avoid SOQL Injection errors.

  • 1
    thank you @mohith its working good
    – vijay
    Nov 27, 2022 at 7:34

You must log in to answer this question.

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