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
Amit Jain 5Amit Jain 5 

Manipulating Records with DML

The Trailhead challenge is to create a metohd for inseting accounts.

I have the follwing code:

public class AccountHandler {

   public static Account insertNewAccount (String accName){ 

   if(accName!=''){    
       try{
           Account a = new Account(Name=accName);
           insert a;
           System.debug('Account created');
           return a;
       } catch(Exception e){
           System.Debug('Account not created');
           return null;
       }
   } else {
       return null;
   }
  }    
}

This runs fine in Anonyomous window, but when I check the challenge from Trail head it thorws this 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 0019000001duAuoAAE; first error: DELETE_FAILED, Your attempt to delete My Test Account could not be completed because it is associated with the following cases.: 00001066 : []
Best Answer chosen by Amit Jain 5
Amit Jain 5Amit Jain 5
I figured out the problem: 
The issue was there was a trigger on Account object, I made the trigger inactive and then was able to pass the trailhead module.
Thanks Vivek for taking time to respond.

All Answers

Bhaswanthnaga vivek vutukuriBhaswanthnaga vivek vutukuri

My wild guess is may be your org has a dupchecker that deletes the old records with any new record come with the similar name or some other prgrm is deleting records ?? otherwise their is no way for delete to execute.

Once check the account with '0019000001duAuoAAE' is having the same name of the record you are trying to insert ?

 

Amit Jain 5Amit Jain 5
I figured out the problem: 
The issue was there was a trigger on Account object, I made the trigger inactive and then was able to pass the trailhead module.
Thanks Vivek for taking time to respond.
This was selected as the best answer