2

I have created a class for api request. I am also sending a parameter in url while requesting for HttpGet. How can I get the value from the url in a HttpGet method. When I added the RestRequest req, RestResponse res as parameter to my apex method I am getting an error

Error: Compile Error: Invalid type: HTTP GET/DELETE methods do not support parameters at line 4 column 26

Can anyone help me out on this issue. This is my apex class.

@RestResource(urlMapping='/mycall')
global class mycallclass{
  @HttpGet
  global static String getmycall(RestRequest req, RestResponse res) {
    String name = RestRequest.params.get('name');
    return 'WooW Success';
  }
}
2

You can access the params map via static fields like this:

Map<String, String> params = RestContext.request.params;
String name = params.get('name');

(Remove the getmycall method parameters you presently have in your code.)

1

You can send the parameter through the URL, and get it by using RestContext.request like this:

@RestResource(urlMapping='/mycall/*')
global class mycallclass {
    @HttpGet
    global static String getmycall() {
        RestRequest req = RestContext.request;
        // Get name from url (represented by the * sign)
        String name = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);

        // Do Stuff here...

        return 'WooW Success ' + name;
    }
}
  • 1
    Note there is a String.substringAfterLast (instance) method. – Adrian Larson Jul 7 '16 at 21:46

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.