You need to sign in to do that
Don't have an account?
Ramana123
System.DmlException: Insert failed. First exception on row 1; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [LastName]: [LastName]
I have given all required field values but still throwing that error
@isTest
private class UpdatingAccountRelatedContactsCount_Test {
static Testmethod void accountRelatedContacts()
{
List<Contact> conList = new List<Contact>();
Account Acc = New Account();
Acc.Name = 'Sai';
insert Acc;
Contact con = new Contact();
con.LastName = 'Test1';
con.AccountId = Acc.Id;
con.Sum__c = 100;
conList.add(con);
Contact con1 = new Contact();
con.LastName = 'Test2';
con1.AccountId = Acc.Id;
con1.Sum__c = 200;
conList.add(con1);
insert conList;
System.debug('aaaaaaaaaaaaaaa'+conList);
// delete con1;
Test.StartTest();
TriggerHelperClass obj = new TriggerHelperClass();
update conList;
Test.StopTest();
}
}
@isTest
private class UpdatingAccountRelatedContactsCount_Test {
static Testmethod void accountRelatedContacts()
{
List<Contact> conList = new List<Contact>();
Account Acc = New Account();
Acc.Name = 'Sai';
insert Acc;
Contact con = new Contact();
con.LastName = 'Test1';
con.AccountId = Acc.Id;
con.Sum__c = 100;
conList.add(con);
Contact con1 = new Contact();
con.LastName = 'Test2';
con1.AccountId = Acc.Id;
con1.Sum__c = 200;
conList.add(con1);
insert conList;
System.debug('aaaaaaaaaaaaaaa'+conList);
// delete con1;
Test.StartTest();
TriggerHelperClass obj = new TriggerHelperClass();
update conList;
Test.StopTest();
}
}
Can you check if you are getting this error even when you are trying to insert from the anonymous window and also as you have used system.debug are you able to see the LastName in the list of contact in debug logs?
Looking forward to your response.
Thanks.
you made some mistake replace your second contact object with following code. you forget add con1 in lastName.
let me know if it helps you and marking it as best.
Thank you