+ Start a Discussion
Lakshmi_lb14447Lakshmi_lb14447 

Query on using REST API in Visualforce

I am trying to use REST API "Query" resource to fetch some data from Account object. The respective pseudo-code is as follows

var strSOQL = '/services/data/v29.0/query?q=SELECT+Id,Name,Phone+FROM+Account+WHERE+Name+LIKE+\'' + nameKeyj + '%\'' + '+ORDER+BY+Name+LIMIT+20' ;


$.ajax(strSOQL,        
       {
        beforeSend: function(xhr)
          {
              .......
       .......

          },
        success: function(response)
          {
              .......
       .......
                                                       
          },

        error: function(jqXHR, textStatus, errorThrown)
          {
   
              .......
              .......
          }
   
        });

In the above code, nameKeyj is a variable containing the value inputted by the user on the visualforce page.

For ex, if the user typed in 'a', the resulting query seen in the debugger is 

SELECT+Id,Name,Phone+FROM+Account+WHERE+Name+LIKE+%27a%%27+ORDER+BY+Name+LIMIT+20

I am always getting 400: Bad Request from the server, and my doubt is on the %27 characters which the server might be considering as invalid and unable to decode them.

Does the REST API "Query" resource supports all kinds of SOQL queries or is there any resriction of not using LIKE verb in the query.

Could someone please provide some idea on this?


Best Answer chosen by Lakshmi_lb14447
Lakshmi_lb14447Lakshmi_lb14447
Thanks Magu for your reply. But my question is simple and more particular about how to send the URI as is in the HTTP request. Anyways the issue is resoved now.

All Answers

MagulanDuraipandianMagulanDuraipandian
This may be useful to you

http://www.infallibletechie.com/2014/03/sample-program-to-query-records-using.html

If this solves your problem, kindly mark it as the best answer.

Regards,
Magulan
http://www.infallibletechie.com
Lakshmi_lb14447Lakshmi_lb14447
Thanks Magu for your reply. But my question is simple and more particular about how to send the URI as is in the HTTP request. Anyways the issue is resoved now.
This was selected as the best answer