+ Start a Discussion
Daniel RobertsDaniel Roberts 

Apex Coding for Admins: Create a Trigger

I can't get the Workbench to create accounts. 
All I am doing is copying code, so I'm not sure where it went wrong. I'm suspecting my object creation is not correct. 
When I attempt to complete the challenge right before this one (title: ​Use DML to Persist sObjects to the Database) I get the following error: 
 
EXCEPTION: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Account number must be 8 characters long.: []
STACKTRACE: AnonymousBlock: line 8, column 1
LINE: 8 COLUMN: 1

The code I i'm using in Workbench to create the Recruiting Account: 
 
//Instantiate an object called acct from the sObject Account class
Account acct = new Account();
    
//Set the attribute name of the acct object to Recruiting
acct.name='Recruiting';
    
//Persist the acct object to the DB using DML
Database.insert(acct);
Any help? 

Thanks, 
 
Steven NsubugaSteven Nsubuga
The Name field of the Account object is currently set to 8 characters in your org. Change it.
Abdul KhatriAbdul Khatri
I think you have a validation rule for the Account object where it is looking at the Account Number Length. Please dactivate that validation rule if you are not expecting anything like that.
Daniel RobertsDaniel Roberts
@Steven Nsubuga Thanks for the suggestions but the Name field is not editable. 

@Abdul Khatri, I don't have any validation rules on my Account Number. User-added image 
Abdul KhatriAbdul Khatri
Please check on the Object Level Account and not on the Field Level.