You need to sign in to do that
Don't have an account?
Giri Kumar B
I am writting wrapper class display record
I have a requirement to display the record account and contact . i am writing a wrapper class in account and contact to display record
my class
public class conacc {
public List<MyWrapper> wrapper {get; set;}
public List<Account> accLst1 {get; set;}
public List<Contact> conLst1 {get; set;}
public conacc ()
{
accLst1 = [select id,Name from Account ] ;
conLst1 = [select Id,Name from contact where AccountId IN : accLst1 ] ;
wrapper = new List<MyWrapper>() ;
for(Integer i=0 ; i < 20; i++)
wrapper.add(new MyWrapper( conLst1, accLst1[i])) ;
}
public class MyWrapper
{
public Account accRec1 {get; set;}
public List<Contact> conRec1 {get; set;}
public MyWrapper( List<Contact> con ,Account acc )
{
accRec1 = acc ;
conRec1 = con ;
}
}
}
i am try to write the test class in wrapper class hit error
test class
@istest
public class wraptest {
@istest
public static void mains(){
/* i am try to record are insert but they are hit error Constructor not defined
Which record i am insert for exp:
account a = new account();
a.name = "test1";
insert a;`enter code here`
i am not understand how to write this wrapper test class
*/
conacc.MyWrapper con = new conacc.MyWrapper();
}
}
my class
public class conacc {
public List<MyWrapper> wrapper {get; set;}
public List<Account> accLst1 {get; set;}
public List<Contact> conLst1 {get; set;}
public conacc ()
{
accLst1 = [select id,Name from Account ] ;
conLst1 = [select Id,Name from contact where AccountId IN : accLst1 ] ;
wrapper = new List<MyWrapper>() ;
for(Integer i=0 ; i < 20; i++)
wrapper.add(new MyWrapper( conLst1, accLst1[i])) ;
}
public class MyWrapper
{
public Account accRec1 {get; set;}
public List<Contact> conRec1 {get; set;}
public MyWrapper( List<Contact> con ,Account acc )
{
accRec1 = acc ;
conRec1 = con ;
}
}
}
i am try to write the test class in wrapper class hit error
test class
@istest
public class wraptest {
@istest
public static void mains(){
/* i am try to record are insert but they are hit error Constructor not defined
Which record i am insert for exp:
account a = new account();
a.name = "test1";
insert a;`enter code here`
i am not understand how to write this wrapper test class
*/
conacc.MyWrapper con = new conacc.MyWrapper();
}
}
public class testclass
{
public static void mains(){:
account a = new account();
a.name = "test1";
insert a;
contact objCon = new Contact();
con.lastname = 'TestCon';
con.Accountid = a.id';
insert con;
conacc.MyWrapper wraptst = new conacc.MyWrapper(con);
}
}
public List<Contact> conRec1 {get; set;}
public MyWrapper( List<Contact> con ,Account acc )
{
accRec1 = acc ;
conRec1 = con ;
}
this is not useable code friend.
Read this article - http://www.infallibletechie.com/2015/03/sample-wrapper-class-using-apex-in.html
you can try bellow code it is working
@istest
public class aaatestclass
{
static testmethod void mytest()
{
account a = new account();
a.name = 'test1';
insert a;
List<contact> conlist = new List<contact>();
contact objCon = new Contact();
objCon.lastname = 'TestCon';
objCon.Accountid = a.id;
conlist.add(objCon);
contact objCon1 = new Contact();
objCon1.lastname = 'TestCon';
objCon1.Accountid = a.id;
conlist.add(objCon1);
insert conlist;
//conacc obj = new conacc();
conacc.MyWrapper wraptst = new conacc.MyWrapper(conlist,a);
}
}
@istest
public class contestclass
{
static testmethod void mytest()
{
list<account> m = new list<account>();
account md = new account();
md.name = 'test3';
m.add(md);
account a = new account();
a.name = 'test1';
m.add(a);
insert m;
List<contact> conlist = new List<contact>();
contact objCon = new Contact();
objCon.lastname = 'TestCon';
objCon.Accountid = a.id;
conlist.add(objCon);
contact objCon1 = new Contact();
objCon1.lastname = 'TestCon';
objCon1.Accountid = a.id;
conlist.add(objCon1);
insert conlist;
//conacc obj = new conacc();
// list<account> mo = [select id,name from account];
// list<contact> con = [select id,name from contact where account id = '']
conacc.MyWrapper wraptst = new conacc.MyWrapper(conlist,a);
}
}
If your problem has solved mark as a best answer.
Thank you