1

I have a Visualforce page using a HTML-JS (ExtJS) Grid with a custom Apex REST handler class in the backend.

To allow send request from VF to the REST service, I have to use the Salesforce-Proxy-Endpoint in the request headers, and it works ok but the query string parameters are not available in the REST resource class.

An example of a request done from the VF:

GET /services/proxy?_dc=1431678948367&page=1&start=0&limit=25 HTTP/1.1
Host: c.eu0.visual.force.com
Connection: keep-alive
SalesforceProxy-Endpoint: https://emea.salesforce.com/services/apexrest/gridRest/Contact
Accept: application/json
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36
Authorization: OAuth 00D20000000n1MZ!AQgAQO.xI5HF097PRfhpufQbHWQh4TntZHGaPvSsH4eI6M3SXQQylCjPpl9GggIIt3TOMNGapAICS6NlVvk.yoycYcb4hfG.
Referer: https://c.eu0.visual.force.com/apex/testGrid
Accept-Encoding: gzip, deflate, sdch
Accept-Language: es,en;q=0.8
Cookie: BrowserId=uLbA95_yT1ah5GiahtA46Q; umps_clientId=*************; sid=00D20000000n1MZ!AQgAQK9lwoD_EDL.hygtauWD5AtHdokzBWTJQsylVlyAUtRb8uaaJBbXkjd1b1v71OIH.rUri.XrU2O5NeeYK7_KBIgVbXRO; sid_Client=*********; clientSrc=*********; inst=APP2

As you can see, 4 parameters are sent to the proxy (_dc, page, start and limit) but the proxy does not forward this parameters to my custom REST Service:

@RestResource(urlMapping='/gridRest/*')
global class Grid_Rest_Controller {

    @HttpGet
    global static String doGet() {
        System.debug(LoggingLevel.ERROR, 'Request doGet --> ' +  RestContext.request);
        System.debug(LoggingLevel.ERROR, 'response doGet --> ' +  RestContext.response);

        String offset = RestContext.request.params.get('start');
        String lim = RestContext.request.params.get('limit');
        String page = RestContext.request.params.get('page');
        System.debug(loggingLevel.Error, '*** offset: ' + offset);
        System.debug(loggingLevel.Error, '*** lim: ' + lim);
        System.debug(loggingLevel.Error, '*** page: ' + page);

        return 'GET';
    }   
}

When the response gets back to the browser, I can see the "GET" but I can not use the querystring parameters in my service (Debug log output is always null)

If I do a request directly to my service by using SOAP-UI, I can get the parameters, so I'm pretty sure that the proxy is "eating" that params.

Should I use another header to force the proxy to forward the querystring? I couldn't find documentation for this topic on the Internet.

Any suggestions?

Thanks in advance!

  • Not to second guess you or anything, but is there a reason you're not using JS Remoting? No proxy, no API call limit consumption. – pchittum May 15 '15 at 10:18
  • @Peter I just wanted to do it REST for simplicity, but now I know that Visualforce creates ExtJS RemotingProviders when the page controller has @ RemoteAction methods so i guess it'll be easy to hook with ExtJS Grid. Thanks – Marclg May 15 '15 at 17:01

Your Answer

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

Browse other questions tagged or ask your own question.