Test Class – set object field value through Controller

There are situation when you want to set the record field value in writing test class for a controller using VF page.

Account testAccount = new Account(Name=’TestAcc’);
insert testAccount;

Contact con = new Contact();
con.firstName = ‘Test First’;
con.AccountId = testAccount.Id;
insert con;

PageReference pref = Page.ContactClone;
ApexPages.StandardController con = new ApexPages.StandardController(con);
ContactClone ext = new ContactClone(con);
ext.contact.LastName = ‘TestLast’;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s