+ Start a Discussion
anvesh@force.comanvesh@force.com 

How to include this piece of code in Test class ?

I want to write Test class for  below controller class code. Pleease help me  how to write in Test Class.

tList;
        }
        set;
    }
public List<Building_Owner__c> contactList {
        get {
            if (contactList == null) {
                contactList = [Select id,Name,Address_1__c,Address_2__c,City__c,Contractor_Branch_Location__c,Company_Company_Location12__c,Contractor_Company_Location__c,Country__c,Email_Address__c,First_Name__c,Last_Name__c,Phone_Number__c,Postal_Code__c,State__c,Time_Zone__c from Building_Owner__c];
            }
            return contac

 
Mudasir WaniMudasir Wani
Hi Anvesh,

Create few records of Building_Owner__c and then call the method.
 
//Create Building_Owner__c recordsin the test class.
Building_Owner__c  buildingOwner = new Building_Owner__c();
buildingOwner.Name = 'test';
buildingOwner.Address_1__c='Location';
....
....
...
...
buildingOwner.State__c = 'StateTest';
insert buildingOwner;
//Similarly create few more
and then call contactList() method

Please mark this as solution if this solves your problem, So that if anyone has this issue this can help.
 
sandeep@Salesforcesandeep@Salesforce
Hi, 

If this is only the piece of code then you can just call this method but if this contactList is being used further then you should have data creation before calling it. 

Thanks 
Sandeep Singhal
 
anvesh@force.comanvesh@force.com
I have created the same but while calling giving error like that  Method or incorrect signature while calling contact list....

buildingOwner.contactlist();