+ Start a Discussion
Jean Grey 10Jean Grey 10 

Method defined as TestMethod do not support web service callouts, but I'm not using a callout

I'm getting this error but my code does not have any callouts. I received the same error when I tried to deploy with default test settings, which is what we always use. None of the test classes that threw an error are using callouts. How do I fix this? See code below of one of the test classes that gave an error.
 
@isTest(seeAllData=true)

public class countOppsTest {

    static testMethod void validateTrigger(){
        Test.startTest();

        DateTime dateNow = system.now();
        Date dateToday = system.today();

        Account acct = new Account(
            name = 'Test Account'
            );
        insert acct;

        Contact cont = new Contact(
            accountId = acct.id,
            firstName = 'Test',
            lastName = 'Contact',
            title = 'Test'
            );
        insert cont;
        
        Goals__c goal = new Goals__c(
            Name = 'Test Goal',
            Amount__c = 1000,
            Date__c = dateToday,
            Active__c = TRUE,
            Opportunity__c = NULL
            );
        insert goal;

        Opportunity opp = new Opportunity(
            Name = 'Test Opp',
            StageName = 'In Purchasing',
            CloseDate = dateToday,
            Amount = 1400,
            AccountId = acct.Id,
            LeadSource = 'Other'
            );
        insert opp;
        
        opp.StageName = 'Closed–Won';
        opp.Closed_Won_Reason__c = 'Test';
        opp.Closed_Won_Explanation__c = 'Test';
        update opp;
        
        ID sysAdm = [SELECT Id FROM Profile WHERE Name = 'System Administrator'].Id;
		//user test data
		List<User> userList = new List<User>();
		User u = new User(ProfileId = sysAdm,LastName = 'last',Email = 'testuser@test.com',
                          Username = 'testuser@test.com' + System.currentTimeMillis(),
                          CompanyName = 'TEST',Title = 'title',Alias = 'alias',
                          TimeZoneSidKey = 'America/Los_Angeles',EmailEncodingKey = 'UTF-8',
                          LanguageLocaleKey = 'en_US',LocaleSidKey = 'en_US');
		userList.add(u);
        insert userList;
        
        system.debug('opp '+opp+' goal '+goal);

		system.assertEquals(goal.Amount__c, 1000);

        
    }
}

 
Best Answer chosen by Jean Grey 10
PawanKumarPawanKumar
Hi Jean Grey,

If you are getting this error means somewhere after update/insert it callout is happening. It could be in the process builder(as Apex)/ Trigger on the following objects. Please check below object's Trigger/process builder for any callout.

Account
Contact
Goals__c 
Opportunity
User

The above object based on your code samples.

Please let me know if it helps you. Thanks.

Regards,
Pawan Kumar
 

All Answers

Jean Grey 10Jean Grey 10
edit - I received the same error for 8 different tests, none of which contain a callout. The code I'm deploying does not contain a callout either.
PawanKumarPawanKumar
Hi Jean Grey,

If you are getting this error means somewhere after update/insert it callout is happening. It could be in the process builder(as Apex)/ Trigger on the following objects. Please check below object's Trigger/process builder for any callout.

Account
Contact
Goals__c 
Opportunity
User

The above object based on your code samples.

Please let me know if it helps you. Thanks.

Regards,
Pawan Kumar
 
This was selected as the best answer
Jean Grey 10Jean Grey 10
Thank you Pawan, that makes sense. It's strange because I've been deploying code to production with default testing for several months and this is the first time this has happened. Did something change with Salesforce or does this just mean that someone added a process or code with a callout?

Irregardless, if I just write a test class that will solve the problem, correct? 
Jean Grey 10Jean Grey 10
I think I found the new managed package that is making callouts. If I can get in touch with the developer there, they can just add some code to exclude the callout if test is running or do a mock callout, is that right?
PawanKumarPawanKumar
Good to know you got the root cause. Since the package is managed one so I would suggest set mock in your class.

 
PawanKumarPawanKumar
Yes, you can get in touch with the developer there, they can just add some code to exclude the callout if test is running or do a mock callout.
since managed package code cannot be changed/viewed so chances to exclude callout is less. Other one will work.
PawanKumarPawanKumar
Hey Jean,

Please mark it best if it was helpful.

Regards,
Pawan Kumar
Jean Grey 10Jean Grey 10
Pawan, how do I add code to my test class to exclude the callout?