You need to sign in to do that
Don't have an account?
seamas li
Rest API request params is null when Testing
Hi Expert,
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();
}
Why I can not get phoneNumber parameter?
Thank you so much.