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
Abhishek Bhardwaj 9Abhishek Bhardwaj 9 

Your attempt to delete My Test Account

Hi,
I'm going through "https://trailhead.salesforce.com/trails/force_com_dev_beginner/modules/apex_database/units/apex_database_dml" module and while implementing the challenge, I am getting following error:
Challenge Not yet complete... here's what's wrong: 
There was an unexpected error in your org which is preventing this assessment check from completing: System.DmlException: Delete failed. First exception on row 0 with id 0017F00000LQrpmQAD; first error: DELETE_FAILED, Your attempt to delete My Test Account could not be completed because it is associated with the following cases.: 00001036 : []

There is no account with name as "My Test Account" & no case with number  as "00001036" visible in my org. Also, I am creating an account record why is it reflecting a message related to deleting of account? Please suggest.

Regards
Best Answer chosen by Abhishek Bhardwaj 9
Amit Chaudhary 8Amit Chaudhary 8
Please check you have any Trigger on Account Object which is creating case object. Please deactivate the same trigger and try again,

All Answers

Abhishek Bhardwaj 9Abhishek Bhardwaj 9
Just to add more, here is the code:
public class AccountHandler {
    public static Account insertNewAccount(string sampleAccountNew){
        try{
            {                
                Account myObj = new Account(name = sampleAccountNew);
                insert myObj;
                System.debug('Record inserted successfully');
                return myObj;
            }
            
        }
        catch(DmlException e){
            System.debug('Error occured while creating account - '+e.getMessage());
            return null;
        }
        
    }
}
Ajay K DubediAjay K Dubedi

Hi Abhishek,

Please try this hope it will help you.

public class AccountHandler {
    public static Account insertNewAccount(String strName){
        if(strName == null){
            return null;
        }else{
                Account acc = new Account();
                acc.Name = strName;
               // insert acc;
                return acc;
         
        }
    }
}


Mark as a best if it helps you.

Regards,

Ajay

Amit Chaudhary 8Amit Chaudhary 8
Please check you have any Trigger on Account Object which is creating case object. Please deactivate the same trigger and try again,
This was selected as the best answer
Abhishek Bhardwaj 9Abhishek Bhardwaj 9
Silly me, deactivated the trigger and worked wonders. Thank You @Amit Chaudhary 8