My requirement is to call an external REST based service from a trigger. This service has been implemented with the GET method. I have finished the code for the trigger and the class.

Now I am creating test classes and a mock in place of the callout. The mock needs to send two separate responses. A success response or a failure response. Here is the mock I am currently writing.

global class RestCalloutMockImpl implements HttpCalloutMock
    global HTTPResponse respond(HTTPRequest req) 
        HttpResponse res = new HttpResponse();
        System.Debug('Endpoint contains '+ req.getEndpoint()); //No query string parameters here.
        System.Debug('Method contains '+ req.getMethod()); //GET
        System.Debug('Body contains ' + req.getBody)); //NULL
        //PSEUDOCODE follows. This is where I want to read the query string paramter values.
        if(check for parameter value here)
        {   //Simulate Failure here.
            res.setBody('{"ErrorMessage":"Life is Short!","ResultValue":"Failure"}');
        return res;


I have been through the documentation on the HttpRequest class. I could not find any method that will output the parameters sent on the query string.

If the calling method is a POST, the getBody() method can be used to see read the contents.

I have tried to use the RestContext class, but the value for that is NULL.


You can use the PageReference class to read the query string, if any, from the URL:

PageReference ref = new PageReference(req.getEndpoint());

If the class performing the callout does not specify a query string, then ref.getParameters() will contain no values.

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.