You need to sign in to do that
Don't have an account?
sakthidharan Ambayiram
//Facing the below error when i try to create a new Account with triggers
//Requirement : we need to create a Contact record every time when you create a new Account
*************
trigger AccountTrigger on Account (after insert) {
List<Contact> ContactList=new List<Contact>();
for(Account a: Trigger.new)
{
Contact C=new Contact();
C.LastName=a.Name;
ContactList.Add(C);
}
insert ContactList;
}
***************************
//Facing the below error when i try to create a new Account
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger AccountTrigger caused an unexpected exception, contact your administrator:
AccountTrigger: execution of AfterInsert caused by: System.DmlException: Insert failed.
First exception on row 0; first error:
FIELD_CUSTOM_VALIDATION_EXCEPTION, u cant insert anew record without email: []: Trigger.AccountTrigger: line 9, column 1
*************
trigger AccountTrigger on Account (after insert) {
List<Contact> ContactList=new List<Contact>();
for(Account a: Trigger.new)
{
Contact C=new Contact();
C.LastName=a.Name;
ContactList.Add(C);
}
insert ContactList;
}
***************************
//Facing the below error when i try to create a new Account
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger AccountTrigger caused an unexpected exception, contact your administrator:
AccountTrigger: execution of AfterInsert caused by: System.DmlException: Insert failed.
First exception on row 0; first error:
FIELD_CUSTOM_VALIDATION_EXCEPTION, u cant insert anew record without email: []: Trigger.AccountTrigger: line 9, column 1
Regards,
Khan Anas
All Answers
Greetings to you!
Seems like there is some validation on Email or it is a required field. Please try the below code, I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
Thanks for ur response.
there is no field like Email in Account Object.
Still facing the same issue.
Regards,
Khan Anas
There is a trigger in Contact object for email, beacuse of that it is throwing error and it is working fine now