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
srujith chintha 4srujith chintha 4 

Now that you’ve added the test utility class, modify the test class to take advantage of this class. In the TestAccountDeletion class, replace the block that starts with // Test data setup and ends with insert opp; with:

@isTest private class TestAccountDeletion { @isTest static void TestDeleteAccountWithOneOpportunity() { // Test data setup // Create one account with one opportunity by calling a utility method Account[] accts = TestDataFactory.createAccountsWithOpps(1,1); // Perform test Test.startTest(); Database.DeleteResult result = Database.delete(accts[0], false); Test.stopTest(); // Verify that the deletion should have been stopped by the trigger, // so check 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()); } }
 1.when i am trying in developer console its showing TestDataFactory variable does not exit
PriyaPriya (Salesforce Developers) 

Hi Srujith,

The code you have provided is not in readable format. Can you again provide your code?

Regards,

Priya Ranjan

Ankit Maini.Ankit Maini.
Check for TestDataFactory class exist in org or not, if it is exist check for createAccountsWithOpps method with same type of parameters.
If not than create it before writing test class.