You need to sign in to do that
Don't have an account?
AlisonR
Test Class for Standard Controller Extension
I'm new to VF and created my first VF extension:
public class LeadSalesActH { private final Lead ld; public LeadSalesActH(ApexPages.StandardController stdController) { this.ld = (Lead)stdController.getRecord(); } public String getName() { return 'LeadSalesActH'; } public Lead getLead() { return [select id, name, ownerid, (select subject, whatid, whoid, activitydate, LVM__c, ownerid, lastmodifieddate from ActivityHistories where ownerid not in ('00530000000vpI1') order by activitydate DESC ) //filter out marketing actvities from Lead where id = :ApexPages.currentPage().getParameters().get('id')]; } }
I started on my test class but I'm getting stuck on the getLead() tests. Can someone put me in the right direction?
Test Class:
@isTest private class ExtendObjectTest { static testmethod void constructorTest() { // set up some test data to work with Lead ld = new Lead(LastName='Test', Company='Test1', Status='New'); insert ld; // start the test execution context Test.startTest(); // set the test's page to your VF page (or pass in a PageReference) Test.setCurrentPage(Page.leadsales); // call the constructor LeadSalesActH controller = new LeadSalesActH(new ApexPages.StandardController(ld)); // stop the test Test.stopTest(); } }
Hi,
you need to call those functions from your test class. Try this now.
@isTest
private class ExtendObjectTest {
static testmethod void constructorTest() {
// set up some test data to work with
Lead ld = new Lead(LastName='Test', Company='Test1', Status='New');
insert ld;
// start the test execution context
Test.startTest();
// set the test's page to your VF page (or pass in a PageReference)
Test.setCurrentPage(Page.leadsales);
// call the constructor
LeadSalesActH controller = new LeadSalesActH(new ApexPages.StandardController(ld));
controller.getName();
controller.getlead();
// stop the test
Test.stopTest();
}
}
All Answers
Hi,
you need to call those functions from your test class. Try this now.
@isTest
private class ExtendObjectTest {
static testmethod void constructorTest() {
// set up some test data to work with
Lead ld = new Lead(LastName='Test', Company='Test1', Status='New');
insert ld;
// start the test execution context
Test.startTest();
// set the test's page to your VF page (or pass in a PageReference)
Test.setCurrentPage(Page.leadsales);
// call the constructor
LeadSalesActH controller = new LeadSalesActH(new ApexPages.StandardController(ld));
controller.getName();
controller.getlead();
// stop the test
Test.stopTest();
}
}
Awesome, that worked perfectly.
Follow up question:
I'm now getting an error when I run the test "System.QueryException: List has no rows for assignment to SObject" is there something I need to add to my controller extension to stop this from failing?
Nevermind, I figured it out. Here's my modified Controller Extension: