• Oz Avrahami
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
Hi,
I'm new in apex and need some help,


I write a trigger that creates a new account every time that I created an account:
trigger AccountParent on Account (after insert) {
    
    List<Account> acc = new List<Account>();
    
    for (Account a : Trigger.new) {
        Account ac = new Account();
        ac.Name = a.Description;
        ac.Parent__c = a.Name;
        acc.add(ac);
    }
    
    if (acc.size()>0) {
        insert acc;
    }
}

but when i create account i get an error:
AccountParent: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AccountParent: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Name]: [Name] Trigger.AccountParent: line 13, column 1: [] Trigger.AccountParent: line 13, column 1

why?? 
 
Hi,
I'm new in apex and need some help,


I write a trigger that creates a new account every time that I created an account:
trigger AccountParent on Account (after insert) {
    
    List<Account> acc = new List<Account>();
    
    for (Account a : Trigger.new) {
        Account ac = new Account();
        ac.Name = a.Description;
        ac.Parent__c = a.Name;
        acc.add(ac);
    }
    
    if (acc.size()>0) {
        insert acc;
    }
}

but when i create account i get an error:
AccountParent: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AccountParent: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Name]: [Name] Trigger.AccountParent: line 13, column 1: [] Trigger.AccountParent: line 13, column 1

why??