Skip to main content
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();

    }

}

 
3 answers
  1. Mar 3, 2021, 6:34 AM
    hi srikanth,

    you made some mistake replace your  second contact object with following code.

    Contact con1 = new Contact();

    con1.LastName = 'Test2';

    con1.AccountId = Acc.Id;

    con1.Sum__c = 200;

    conList.add(con1);

    insert conList;

    you forget add con1 in lastName.

    let me know if it helps you and marking it as best.

    Thank you

     
0/9000