You need to sign in to do that
Don't have an account?
Shubham Sinha 49
Write a test class for Custom Controller
Hi,
How to write a test class for below code
How to write a test class for below code
public class AccountSelectClassController{ //Our collection of the class/wrapper objects wrapAccount public List<wrapContact> wrapContactList {get; set;} public List<contact> selectedcontacts{get;set;} public string searchtext1{get;set;} public void search(){ if(wrapContactList == null) { wrapContactList = new List<wrapContact>(); for(Contact a: [select Id, name, Phone from contact where lastname like :searchtext1 ]) { // As each Account is processed we create a new wrapAccount object and add it to the wrapAccountList wrapContactList.add(new wrapContact(a)); } } } public void processSelected() { selectedcontacts = new List<contact>(); for(wrapContact wrapContactObj : wrapContactList) { if(wrapContactObj.selected == true) { selectedcontacts.add(wrapContactObj.con); } } } public void clear() { wrapContactList.clear(); } // This is our wrapper/container class. A container class is a class, a data structure, or an abstract data type whose instances are collections of other objects. In this example a wrapper class contains both the standard salesforce object Account and a Boolean value public class wrapContact { public contact con {get; set;} public Boolean selected {get; set;} //This is the contructor method. When we create a new wrapAccount object we pass a Account that is set to the acc property. We also set the selected value to false public wrapContact(contact a) { con = a; selected = false; } } }
Insert a contact.
Build an instance of the controller.
Invoke a method for the controller.
Longer version - not compiled.
Rinse repeat for other methods
Regards
Andrew
HTH
Andrew