You need to sign in to do that
Don't have an account?
seamas li
Can not get REST API request params when testing
Hi Expert,
Why I can not get phoneNumber parameter?
Thank you so much.
I am testing Rest Api Apex code:
@RestResource(urlMapping='/mytest/*')
global with sharing class salesforceRestCall{
@HttpGet
global static String doGet() {
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
system.debug(' RestContext.request.params :: '+ RestContext.request.params);
String phoneNumber=req.params.get('subscriptionId');
String response = processRequest( phoneNumber);
return response;
}
Testing Apex class:
static testMethod void getSubscriptionByPhoneNumberTest() {
test.startTest();
RestRequest req = new RestRequest();
RestResponse res = new RestResponse();
req.requestURI = '/services/apexrest/subscriptions?phoneNumber=416360999';
req.httpMethod = 'GET';
RestContext.request = req;
RestContext.response= res;
String susbscriptionDetail = salesforceRestCall.doGet();
test.stopTest();
}
Why I can not get phoneNumber parameter?
Thank you so much.
I am testing Rest Api Apex code:
@RestResource(urlMapping='/mytest/*')
global with sharing class salesforceRestCall{
@HttpGet
global static String doGet() {
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
system.debug(' RestContext.request.params :: '+ RestContext.request.params);
String phoneNumber=req.params.get('subscriptionId');
String response = processRequest( phoneNumber);
return response;
}
Testing Apex class:
static testMethod void getSubscriptionByPhoneNumberTest() {
test.startTest();
RestRequest req = new RestRequest();
RestResponse res = new RestResponse();
req.requestURI = '/services/apexrest/subscriptions?phoneNumber=416360999';
req.httpMethod = 'GET';
RestContext.request = req;
RestContext.response= res;
String susbscriptionDetail = salesforceRestCall.doGet();
test.stopTest();
}
Thanks so much. And sorry for misunderstand.
I was using : String phoneNumber = req.params.get('phoneNumber');
And I can get phoneNumber by Workbeck , but can not get it by Test method.