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
Ankit Khurana24Ankit Khurana24 

how to test the code...or write test class?

i have written a code for the show this functionality..

There is an custom button on contact record page...on the click of this button an vf page will open which will show 5 fields of this contact and 5 fields of the account associated with this contact..

i have written this code..please help me writing test class for this code..

public class contactdetail
{
public Contact con{get;set;}
public string retid{get;set;}
public PageReference pr;
public List<Contact> contactrecord{get;set;}
public List<Account> cppz;
public List<Contact> oppz;



public contactdetail(ApexPages.StandardController controller)
{
retid=ApexPages.currentPage().getParameters().get('id');
this.con=(Contact)controller.getRecord();
pr=new PageReference('/'+retid);
pr.setRedirect(true);
}
Public PageReference Contactdetails()
{
return pr;
}
public List<Contact> getOppz()
{
Contact con1= [Select id FROM Contact where id = :con.id];
if (con1.id == null)
return null;
oppz = [Select c.FirstName, c.Fax, c.Email, c.Department, c.Birthdate, c.AssistantName From Contact c where c.Id = :con1.id];
return oppz;

}
public List<Account> getCppz()
{
Contact con2= [Select id ,AccountId FROM Contact where id = :con.id];
if (con2 .AccountId == null)
return null;
cppz = [Select a.Type, a.Phone, a.Name, a.CreatedDate, a.Birthday__c From Account a where a.Id = :con2.AccountId ];
return cppz;
}


}