Skip to main content
Whenever a new contact is created for a account update the corresponding account phone with the new contact??

trigger updatephonenocontact on Account (After insert) {

    List <Contact> Con = new List <Contact>();

    For (Account A: Trigger.new){

    Contact C = new Contact();

 

    C.phone= A.phone;

    C.AccountId = A.Id;

    

    Con.add(C);

    }

    

    Insert Con;

}

 im getting this error message 

Error: Invalid Data. 

Review all error messages below to correct your data.

Apex trigger updatephonenocontact caused an unexpected exception, contact your administrator: updatephonenocontact: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Last Name]: [Last Name]: Trigger.updatephonenocontact: line 19, column 1
4 个回答
0/9000