3

RestContext.request.params.get gives null value for Test Class

Following is my code and Debug logs :

APEX CLASS :

 String accountRecordId= RestContext.request.params.get('accountRecordId');   
 System.debug('GetSuccessManagerInfo:'+ accountRecordId);  

TEST CLASS :

 reqExp.requestURI = sfdcBaseURL +'/services/apexrest/SM/myMethod?accountRecordId=' + objAcc.id;  
 System.Debug('-------Nilesh-reqExp.requestURI--'+reqExp.requestURI);

DEBUG LOGS :

USER_DEBUG|[53]|DEBUG|-------Nilesh-reqExp.requestURI--https://yp--DEV.cs15.my.salesforce.com/services/apexrest/SM/myMethod?accountRecordId=001e000000pURpNAAW

|USER_DEBUG|[17]|DEBUG|GetSuccessManagerInfo:null

Any suggestion or help ?

5

You need to actually set the RestContext.request in your test class and then set any params you want through that.

RestContext.request = new RestRequest();
RestContext.request.params.put('accountRecordId', accountRecord.Id);
| improve this answer | |

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.