You need to sign in to do that
Don't have an account?
Test Class for @HttpGet method. Can you please help me out with this? I'm getting an error "Test methods do not support webservice callouts"
Please help me guys. I appreciate your help.
Thanks in advance!
Sandeep Chittineni
@HttpGet global static Account getAccountById() { RestRequest request = RestContext.request; // grab the caseId from the end of the URL String accountId = request.requestURI.substring( request.requestURI.lastIndexOf('/')+1); Account result = [SELECT Id,Name FROM Account WHERE Id = :accountId]; return result; } @HttpDelete global static void deleteAccount() { RestRequest request = RestContext.request; String accountId = request.requestURI.substring( request.requestURI.lastIndexOf('/')+1); Account thisAccount = [SELECT Id FROM Account WHERE Id = :accountId]; delete thisAccount; }
Thanks in advance!
Sandeep Chittineni
Here's a link to it:-
https://salesforce.stackexchange.com/questions/173928/code-coverage-for-httpget-rest-method/173975
Hope it helps.
Thanks
All Answers
Create HTTPCalloutMock class to create a fake response and use it in your testMethods.
Here's a link to it:-
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_testing_httpcalloutmock.htm
Hope it helps, if it does, mark it as solved to keep the community clean.
Thanks
Thanks for your time Meghna! Yes we can use HTTPCalloutMock interface to create a fake cresponse but I need a fake request this is a rest api used to request from external application. Any other suggestions meghna?
Thanks for you once again!
Sandeep Chittineni
Here's a link to it:-
https://salesforce.stackexchange.com/questions/173928/code-coverage-for-httpget-rest-method/173975
Hope it helps.
Thanks
Thanks Meghna! This might be best solution for other developers so that they can find easily. I tried to implement this in my code. And it is throwing an error "Test methods do not support webservice callouts".
Thank you very much for the help Meghna!
//Webservice...
//And Test Class...
This is very strange. My test method is failed and I'm getting this error all the time.
Can you resend back the code you wrote in you console?
Thanks,
Sandee.
It's the same code which you posted previously.
Thanks,
Sandeep