function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AbAb 

Error | Methods defined as TestMethod do not support Web service callouts null

Hello,

I have below error message,

I have no web service calll from the class
 
Methods defined as TestMethod do not support Web service callouts null

 
Best Answer chosen by Ab
ManojjenaManojjena
Hi Sandrine ,

Basically salesforce will not allow to do callout from test class .Either you can use Test.isRunningTest() method in your class code and hard code the response .Which will not do call out from test class .

Or you can use Webservice call out mock 
Check below link .
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts_wsdl2apex_testing.htm

Let me know if it helps !!
Thanks
Manoj

All Answers

ManojjenaManojjena
Hi Sandrine ,

Basically salesforce will not allow to do callout from test class .Either you can use Test.isRunningTest() method in your class code and hard code the response .Which will not do call out from test class .

Or you can use Webservice call out mock 
Check below link .
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts_wsdl2apex_testing.htm

Let me know if it helps !!
Thanks
Manoj
This was selected as the best answer
AbAb
It is strange because, i am just creating new account and inserting it.
There is no callout in this test class
AbAb
@isTest
public class tester_test {
     
      Static testmethod void mytest1 () {


 
    
      Account a = new account(name='abc');
      insert a; 
 
      RecordType rt = [select Id from RecordType where Name = 'XYZ' and SobjectType = 'contact'];
 
      contact c = new contact(lastname='abc',accountid=a.id,recordtypeid=rt.id);
      insert c; 

 
      update c;
 
}

}

above is my test class, i dont see any callout or callout made by related class
ManojjenaManojjena
Hi Sandrine ,

You needs check may be any code is executing while inserting account . May be any out bound message in work flow  or trigger please cross check once .
Thanks
Manoj.

 
Steve CairneySteve Cairney
Sorry to raise this again, but Sandrine, I'm wondering how you got around this in your tester_test class?

I'm working on a controller class test and due to the creation of an object it's causing a web service callout.
AbAb
You have to put the webservice callout code in a Seperate global class and then call this class asynchronyly from test class.
You will need to see above links in thread and soon you will get it.
It took me a while to figure out
Steve CairneySteve Cairney
Thanks Sandrine, I wondered if it was a new class or if you could add it into the class directly.
Systems DevelopmentSystems Development
I'm running into this same issue with a very similar case to Sandrine's test.   

I'm curious what the "web service callout is" in my code (or in Sandrine's code).  It doesn't seem like there is one.
static testMethod void testAccountTrigger() {
    
    List<Account> accounts = new List<Account>{};
    
    for(Integer i =0; i < 5; i++) {
        Account a = new Account(Name = 'Test Account ' + i, QuoteTrackerID__c = i);
        accounts.add(a);
    }
    
    insert accounts;
    
    List<Account> insertedAccounts = [Select Name, QuoteTrackerID__c FROM Account WHERE Id IN :accounts];
    
    for(Account a: insertedAccounts) {
        a.Description = 'This is a test.';
    }
    
    test.StartTest();
    update insertedAccounts;
    test.StopTest();
 }
Systems DevelopmentSystems Development
Ok, after a bit more tracing, I found that I have a trigger that is called after an account update which calls a method in the AccountIntegration class that DOES look like it makes a web service call, updating the account in another system.

So what needs to happen is that there needs to be a test that mocks this update?  
Christopher D. EmersonChristopher D. Emerson
Thanks to "Systems Development" user - that Trigger thing was tripping me up too! Took forever but finally (after your post) I found/fixed the issue blocking me from completing the Trailhead module!