You need to sign in to do that
Don't have an account?
David Durant 5
Web Services Call Out Help
I have a test class and trigger that I have completed. Currently, it is giving me an error on the web services callout. I tried to do some research to understand why it was giving me this error. I know that the piclist field that I am referencing has a web service callout on the lead object but I am refereing to it on the opportunity. I also do not know where or how to even set up the mock callout to allow myself to obtain code coverage. Here is my code:
@isTest public class TestUtilityUpdate{ static testMethod void myTest(){ Account acc= new Account(name='Test - Properties'); insert acc; set<String> strNames = new set<String>{'Los Angeles Department of Water and Power', 'Adams Ranch', 'Amarillo Mutual', 'Anaheim, City of', 'Arcadia, City of' }; List<Opportunity> lstOpp = new List<Opportunity>(); for(String str : strNames) { Opportunity opp = new Opportunity(Water_Agency__c=str,name=str,closedate=system.today(),stagename='Consult to be Scheduled',Accountid=acc.id); lstOpp.add(opp); } insert lstOpp; } }
I hope from some trigger your are doing any HTTP Callout. That is why your test class is failing.
You Can create Mock class like below code :-
You Can use same mock class in your test class like below class :-
Please refer below blog for more details:-
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_testing_httpcalloutmock.htm
And you can use Test.isRunningTest() Method to stop the call out from trigger in case test class is runing
See more detail below :-
https://help.salesforce.com/apex/HTViewSolution?id=000138850&language=en_US (https://help.salesforce.com/apex/HTViewSolution?id=000138850&language=en_US)
Please let us know if this will help you
Thanks
Amit Chaudhary
amit.salesforce21@gmail.com
Where do I start? I saw this example in the developer book but I dont understand how to take my class and impliment the this mock class.
Hi David! I'm running into the same issue on writing the test coverage for a mock callout, did you ever get a response for your question on how to implement the mock call?