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
Michael Chan 28Michael Chan 28 

Test Apex Triggers

In Apex Testing > Test Apex Triggers tutorial,

I would like to run TestAccountDeletion but I encounter the following error:

Methods defined as TestMethod do not support Web service callouts

The code copied and pasted from the tutorial:

@isTest
private class TestAccountDeletion {
    @isTest static void TestDeleteAccountWithOneOpportunity() {
        // Test data setup
        // Create an account with an opportunity, and then try to delete it
        Account acct = new Account(Name='Test Account');
        insert acct;
        Opportunity opp = new Opportunity(Name=acct.Name + ' Opportunity',
                                       StageName='Prospecting',
                                       CloseDate=System.today().addMonths(1),
                                       AccountId=acct.Id);
        insert opp;
        
        // Perform test
        Test.startTest();
        
        Database.DeleteResult result = Database.delete(acct, false);
        
        Test.stopTest();
        
        // Verify 
        // In this case the deletion should have been stopped by the trigger,
        // so verify that we got back an error.
        System.assert(!result.isSuccess());
        System.assert(result.getErrors().size() > 0);
        System.assertEquals('Cannot delete account with related opportunities.',
                             result.getErrors()[0].getMessage());
    }
}

 
Naveen IlaNaveen Ila
I hope, you are making an API call while performing DML on Account/Opportunity through trigger/process builder. 

We can delete an Account with opportunities, unless it contains atleast 1 closed won opportunity. 
SandhyaSandhya (Salesforce Developers) 
Hi,

I have just tried with the same code and I am able to run.I would suggest you check for other triggers if you have and make them inactive and only this trigger as active as noted in the content.

I this does not work try in new trailhead playground.

Please mark it as solved if my reply was helpful. It will make it available for other as the proper solution.
                                             
Best Regards
Sandhya