[SalesForce] Rest api HttpGet issue

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';
  }
}

Best Answer

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.)

Related Topic