You need to sign in to do that
Don't have an account?
deeksharth srivastava
Help me to write a test class for this wrapper class
public class PropertyRelatedController
{
// declaration Start
public List<String> str1 ;
public List<SelectOption> countrieLst {get;set;}
String newSetStr ;
String Selectedstr;
public string ContactIds{get;set;}
// public string ContactIds1{get;set;}
list<Contact> con =new list<Contact>();
list<CampaignMember> cmem = new list<CampaignMember>();
public TTL_Residential__Property__c cp{get;set;}
Public List<WrapperClassEx> WrapperList{get;set;}
public list<string> ContactId = new list<string>();
public list<string> ContactId1 = new list<string>();
public list<string> ContactId2 = new list<string>();
Set<Id> accountId = new Set<ID>();
public string selectedValue{get;set;}
// Controller start from here
public PropertyRelatedController(ApexPages.StandardSetController standardController)
{
for(Sobject standcont:standardController.getSelected())
{
accountId.add(standcont.id);
}
cp = new TTL_Residential__Property__c();
selectedValue='';
system.debug('chechk'+Selectedstr);
// ContactIds = new list<string>();
ContactId.clear();
}
public void getContactNames()
{
Selectedstr = selectedValue;
getwrapperObj();
}
public List<SelectOption> getItems()
{
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('All','--All--'));
options.add(new SelectOption('Primary Owner or Owner','Primary Owner and Owner '));
options.add(new SelectOption('Primary Owner','Primary Owner'));
options.add(new SelectOption('Owner','Owner'));
return options;
}
// Wrapper Class Starts from Here
Public List<WrapperClassEx> getwrapperObj()
{
WrapperList = New List<WrapperClassEx>();
map<string,TTL_Residential__Property__c> mapofproperty = new map<string,TTL_Residential__Property__c>();
For( TTL_Residential__Property__c propobject : [ select id,name from TTL_Residential__Property__c where id in:accountId ])
{
mapofproperty.put(propobject.id,propobject);
}
set<string> setofid = new set<string>();
map<string,WrapperClassEx> mapofwrapper = new map<string,WrapperClassEx>();
if(Selectedstr != null && Selectedstr!='Primary Owner or Owner' && Selectedstr!='All' )
{
ContactId.clear();
system.debug('cid'+ContactId);
for(TTL_Core__Contact_Role__c contactrole : [select id,TTL_Core__Contact__c,TTL_Core__Contact_Role__c,TTL_Commercial__Property__c,TTL_Core__Contact__r.Account.Name from TTL_Core__Contact_Role__c where TTL_Commercial__Property__c in:mapofproperty.keyset() and TTL_Core__Contact_Role__c =: Selectedstr])
{
ContactId.add(contactrole.TTL_Core__Contact__c);
system.debug('cid2'+ContactId);
if(!setofid.contains(contactrole.TTL_Commercial__Property__c))
{
setofid.add(contactrole.TTL_Commercial__Property__c);
mapofwrapper.put(mapofproperty.get(contactrole.TTL_Commercial__Property__c ).id,New WrapperClassEx(mapofproperty.get(contactrole.TTL_Commercial__Property__c ).name,mapofproperty.get(contactrole.TTL_Commercial__Property__c ).id ));
mapofwrapper.get(contactrole.TTL_Commercial__Property__c).listofcontactrole.add(contactrole);
WrapperList.add(New WrapperClassEx(mapofproperty.get(contactrole.TTL_Commercial__Property__c ).name,mapofproperty.get(contactrole.TTL_Commercial__Property__c ).id ));
}
else
{
mapofwrapper.get(contactrole.TTL_Commercial__Property__c).listofcontactrole.add(contactrole);
}
}
}
Public Class WrapperClassEx
{
public list<TTL_Core__Contact_Role__c > listofcontactrole{get;set;}
Public string propertyname{get;set;}
Public string propertyid{get;set;}
Public WrapperClassEx(string JCity,string propertyid){
this.propertyid = propertyid;
propertyname=JCity;
listofcontactrole = new list<TTL_Core__Contact_Role__c >();
}
}
}
{
// declaration Start
public List<String> str1 ;
public List<SelectOption> countrieLst {get;set;}
String newSetStr ;
String Selectedstr;
public string ContactIds{get;set;}
// public string ContactIds1{get;set;}
list<Contact> con =new list<Contact>();
list<CampaignMember> cmem = new list<CampaignMember>();
public TTL_Residential__Property__c cp{get;set;}
Public List<WrapperClassEx> WrapperList{get;set;}
public list<string> ContactId = new list<string>();
public list<string> ContactId1 = new list<string>();
public list<string> ContactId2 = new list<string>();
Set<Id> accountId = new Set<ID>();
public string selectedValue{get;set;}
// Controller start from here
public PropertyRelatedController(ApexPages.StandardSetController standardController)
{
for(Sobject standcont:standardController.getSelected())
{
accountId.add(standcont.id);
}
cp = new TTL_Residential__Property__c();
selectedValue='';
system.debug('chechk'+Selectedstr);
// ContactIds = new list<string>();
ContactId.clear();
}
public void getContactNames()
{
Selectedstr = selectedValue;
getwrapperObj();
}
public List<SelectOption> getItems()
{
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('All','--All--'));
options.add(new SelectOption('Primary Owner or Owner','Primary Owner and Owner '));
options.add(new SelectOption('Primary Owner','Primary Owner'));
options.add(new SelectOption('Owner','Owner'));
return options;
}
// Wrapper Class Starts from Here
Public List<WrapperClassEx> getwrapperObj()
{
WrapperList = New List<WrapperClassEx>();
map<string,TTL_Residential__Property__c> mapofproperty = new map<string,TTL_Residential__Property__c>();
For( TTL_Residential__Property__c propobject : [ select id,name from TTL_Residential__Property__c where id in:accountId ])
{
mapofproperty.put(propobject.id,propobject);
}
set<string> setofid = new set<string>();
map<string,WrapperClassEx> mapofwrapper = new map<string,WrapperClassEx>();
if(Selectedstr != null && Selectedstr!='Primary Owner or Owner' && Selectedstr!='All' )
{
ContactId.clear();
system.debug('cid'+ContactId);
for(TTL_Core__Contact_Role__c contactrole : [select id,TTL_Core__Contact__c,TTL_Core__Contact_Role__c,TTL_Commercial__Property__c,TTL_Core__Contact__r.Account.Name from TTL_Core__Contact_Role__c where TTL_Commercial__Property__c in:mapofproperty.keyset() and TTL_Core__Contact_Role__c =: Selectedstr])
{
ContactId.add(contactrole.TTL_Core__Contact__c);
system.debug('cid2'+ContactId);
if(!setofid.contains(contactrole.TTL_Commercial__Property__c))
{
setofid.add(contactrole.TTL_Commercial__Property__c);
mapofwrapper.put(mapofproperty.get(contactrole.TTL_Commercial__Property__c ).id,New WrapperClassEx(mapofproperty.get(contactrole.TTL_Commercial__Property__c ).name,mapofproperty.get(contactrole.TTL_Commercial__Property__c ).id ));
mapofwrapper.get(contactrole.TTL_Commercial__Property__c).listofcontactrole.add(contactrole);
WrapperList.add(New WrapperClassEx(mapofproperty.get(contactrole.TTL_Commercial__Property__c ).name,mapofproperty.get(contactrole.TTL_Commercial__Property__c ).id ));
}
else
{
mapofwrapper.get(contactrole.TTL_Commercial__Property__c).listofcontactrole.add(contactrole);
}
}
}
Public Class WrapperClassEx
{
public list<TTL_Core__Contact_Role__c > listofcontactrole{get;set;}
Public string propertyname{get;set;}
Public string propertyid{get;set;}
Public WrapperClassEx(string JCity,string propertyid){
this.propertyid = propertyid;
propertyname=JCity;
listofcontactrole = new list<TTL_Core__Contact_Role__c >();
}
}
}
I've not written all code for you but give you a idea. Please change the data according to your controller.
-Thanks
Ashlekh Gera