You need to sign in to do that
Don't have an account?
Jos Vervoorn
Test class is not touching REST API
Hi,
I have created a simple Rest API endpoint however my test class is not touching the endpoint at all. The API URL mapping is
//** services/apexrest/accounts/0016E00000YNC49/entitlements
@RestResource(urlMapping='/accounts/*/entitlements')
Global with sharing class U4_REST_AccountEntitlements {
@HttpGet
global static Account getAccount(){
and returns entitlement values. Using REST Explorer within workbench it works perfectly but when I run the test class it is not returning any values. In fact ... the result is [REST_AccountEntitlements_TEST].RestResource response:RestResponse:[headers={}, responseBody=null, statusCode=null]
Any help would be much appreciated.
I have created a simple Rest API endpoint however my test class is not touching the endpoint at all. The API URL mapping is
//** services/apexrest/accounts/0016E00000YNC49/entitlements
@RestResource(urlMapping='/accounts/*/entitlements')
Global with sharing class U4_REST_AccountEntitlements {
@HttpGet
global static Account getAccount(){
and returns entitlement values. Using REST Explorer within workbench it works perfectly but when I run the test class it is not returning any values. In fact ... the result is [REST_AccountEntitlements_TEST].RestResource response:RestResponse:[headers={}, responseBody=null, statusCode=null]
Any help would be much appreciated.
Test.startTest(); Id recordId = NewServiceAccount.Id; RestRequest request = new RestRequest(); RestResponse response = new RestResponse(); request.httpMethod = 'GET'; Request.requestURI ='/services/apexrest/accounts/'+NewServiceAccount.Id+'/entitlements'; System.debug(LoggingLevel.Info,'+*+*+*+*+*+*+* '+NewServiceAccount.id); System.debug(LoggingLevel.Info,'[REST_AccountEntitlements_TEST].RestResource response:'+Request.requestURI); RestContext.request = request; RestContext.response = response; System.debug(LoggingLevel.Info,'[REST_AccountEntitlements_TEST].RestResource response:'+response); Test.stopTest();
Try This :
More info :
https://salesforce.stackexchange.com/questions/190707/test-class-for-rest-api-get
Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.
Thanks
Varaprasad
@For SFDC Support: varaprasad4sfdc@gmail.com
Blog: http://salesforceprasad.blogspot.com/
Salesforce latest interview questions :
https://www.youtube.com/channel/UCOcam_Hb4KjeBdYJlJWV_ZA?sub_confirmation=1
All Answers
Try This :
More info :
https://salesforce.stackexchange.com/questions/190707/test-class-for-rest-api-get
Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.
Thanks
Varaprasad
@For SFDC Support: varaprasad4sfdc@gmail.com
Blog: http://salesforceprasad.blogspot.com/
Salesforce latest interview questions :
https://www.youtube.com/channel/UCOcam_Hb4KjeBdYJlJWV_ZA?sub_confirmation=1