function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jayesh Deo 2Jayesh Deo 2 

Method does not exist or incorrect signature: void add(List<Case>) from the type Case

I am getting mentioned error while adding related 10 case records to account record. Please help.


account acc=new account();
acc.name='cognizant';
insert acc;

ID accID=acc.ID;

list <contact> con=new list <contact>();
for(integer counter=1;counter<=5; counter++)
{
    contact cont= new contact();
    cont.lastname='plumber'+counter;
    cont.email='bulky'+counter+'@gmail.com';
    cont.AccountId=accID;
    con.add(cont);
}
insert con;

list <case> caselist=new list <case> ();

for(integer counter=1; counter<=10; counter++)
{
    case cd=new case();
    cd.status='working';
    cd.SuppliedPhone='counter'+counter;
    cd.AccountId=accID;
    cd.add(caselist);
    
}
insert caselist;
 
Gian Piere VallejosGian Piere Vallejos
Replace cd.add(caselist) for caselist.add(cd) before close the second loop.
Sai PraveenSai Praveen (Salesforce Developers) 
Hi,

The main issue in the code is you have to add the case into the caselist but you have done the other way. 

I have corrected it in the below . The error is highlited.
 
account acc=new account();
acc.name='cognizant';
insert acc;

ID accID=acc.ID;

list <contact> con=new list <contact>();
for(integer counter=1;counter<=5; counter++)
{
    contact cont= new contact();
    cont.lastname='plumber'+counter;
    cont.email='bulky'+counter+'@gmail.com';
    cont.AccountId=accID;
    con.add(cont);
}
insert con;

list <case> caselist=new list <case> ();

for(integer counter=1; counter<=10; counter++)
{
    case cd=new case();
    cd.status='working';
    cd.SuppliedPhone='counter'+counter;
    cd.AccountId=accID;
   caselist.add(cd);
    
}
insert caselist;


Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
Jayesh Deo 2Jayesh Deo 2
Thanks for the Solution. It worked! Case method was misaligned.