public class VfController{ private final Contact con;
public VfController(){ con=[select id,name,Account.name,Account.id,Account.billingstreet from contact where id=: Apexpages.currentpage().getParameters().get('id')]; } public contact getCon(){ return con; } public pageReference save(){ update con; return null; } }
Please find below the code for test method of your class:-
public class VfController { private final Contact con; public VfController() { con=[select id,name,Account.name,Account.id,Account.billingstreet from contact where id=: Apexpages.currentpage().getParameters().get('id')]; } public contact getCon() { return con; } public pageReference save() { update con; return null; }
Hi,
Please find below the code for test method of your class:-
public class VfController
{
private final Contact con;
public VfController()
{
con=[select id,name,Account.name,Account.id,Account.billingstreet from contact where id=:
Apexpages.currentpage().getParameters().get('id')];
}
public contact getCon()
{
return con;
}
public pageReference save()
{
update con;
return null;
}
public static testMethod void testVfController()
{
Account a1=new account(name='testaccount',billingstreet='street1');
insert a1;
Contact c1=new contact(firstname='f1',lastname='c1',accountid=a1.id);
insert c1;
ApexPages.CurrentPage().getParameters().put('id', c1.Id);
VfController v1=new VfController();
v1.getcon();
v1.save();
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.