You need to sign in to do that
Don't have an account?
Michael Hedrick 2
Methods defined as TestMethod do not support Web service callouts but not during testing
Hello All,
I have a Class that performs a call out;
Have a test Class and this works fine.
I now have additional Apex triggers to deploy and now its failing on the above Class. The trigger I am deploying is related to the Cases.
The fatal error is on line : HTTPResponse resp = http.send(req);
Methods defined as TestMethod do not support Web service callouts
And this code did deploy to production originally but I deployed with just the Class and test Class.
If anyone can spot the issue or has any suggestions I would greatly appreciate it.
Regards,
M
I have a Class that performs a call out;
Global class CallTrexWebServiceAccountUpdate{ public static Account accounts {get;set;} public static String myresponse{get;set;} webservice static string ABCWebServiceAccountUpdate(String id) { ABCWebServiceAccountUpdateAsync(id); return myresponse; } @future(Callout=true) static void ABCWebServiceAccountUpdateAsync(String id) { System.debug(id); accounts = [SELECT id,Partner_Type__c FROM Account WHERE id =:id]; if(id != null ) { HttpRequest req = new HttpRequest(); Http http = new Http(); req.setMethod('GET'); String url = 'https://blabla/Services.asmx/UpdateAccount?accountId='+id; req.setEndpoint(url); HTTPResponse resp = http.send(req); myresponse = resp.getBody(); } } }
Have a test Class and this works fine.
I now have additional Apex triggers to deploy and now its failing on the above Class. The trigger I am deploying is related to the Cases.
The fatal error is on line : HTTPResponse resp = http.send(req);
Methods defined as TestMethod do not support Web service callouts
And this code did deploy to production originally but I deployed with just the Class and test Class.
If anyone can spot the issue or has any suggestions I would greatly appreciate it.
Regards,
M
All Answers
Should I always consider using the if(!Test.isRunningTest()) syntax in classes that perfomr a Call out?
If not, why did you receommend using it in this scenerio?
Thanks,
M
Please refer this article
. Testing callouts - in your callout code you check to see if you're executing within a unit test context by checking Test.isRunningTest() and instead of getting your callout response from an HttpResponse.send() request, you return a pre-built test string instead.
https://help.salesforce.com/articleView?id=000205831&type=1
Mark it as solved!
So are you saying I should have split the test class into 2 parts?
In your case, your trigger contains web service code which is executing from the test class which is not correct ..
M