You need to sign in to do that
Don't have an account?
Michael 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()); } }
We can delete an Account with opportunities, unless it contains atleast 1 closed won opportunity.
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