You need to sign in to do that
Don't have an account?
SFDCDenver
Cannot get this VF test to work
I have been trying to get this test for this controller extension to work and I am not having any luck whatsoever. Can someone look at the test code and see why i keep getting "Constructor not defined: [ApexPages.StandardController].<Constructor>(Id)"
I am very new to VF pages. Thank you.
Controller
Visual Force Page
Test Code
I am very new to VF pages. Thank you.
Controller
public class DesignationEditorController { /* Controller Notes: Standard override for Add and Save need to exist as list opens and remains in edit mode */ public List<SE_Designation__c> Designations { get; set; } private final Discovery__c ParentDiscovery; public String Blurb { get; set; } //used to get a hold of the record selected for deletion public string SelectedDeleteId { get; set; } public DesignationEditorController(ApexPages.StandardController stdController) { this.ParentDiscovery = (Discovery__c) stdController.getRecord(); refreshDesignations(); } // See 'Controller Notes:' above public void Add() { // Prevent Multiple Blank Records adds refreshDesignations(); boolean goodDesignation = true; for(SE_Designation__c d: Designations) { if(goodDesignation == true && d.Dest_Position__c == Null) goodDesignation = false; } // only add if no blank Dest_Position__c if(goodDesignation == true) { SE_Designation__c newDes = initNewDesignation(); insert newDes; refreshDesignations(); } } // See 'Controller Notes:' above public void Save() { doSave(); return; } private void doSave() { update Designations; } private SE_Designation__c initNewDesignation() { SE_Designation__c d = new SE_Designation__c(); d.Discovery__c = ParentDiscovery.Id; d.Name = 'New'; return d; } private void refreshDesignations() { Designations = [SELECT Id,Dest_Position__c,Dest_Time_Line__c,Dest_Pri_Power_Prod_pick__c,Dest_Pri_Receptacle__c, Dest_Red_Power_Prod_pick__c,Dest_Red_Receptacle__c,Dest_DC_Product_pick__c,Dest_V_Drop__c,Dest_DC_Lug__c,Dest_DC_Term__c, Dest_Cabinet_Footprint__c, Dest_DEMARC__c, Dest_Weight__c, Dest_Cab_Notes__c FROM SE_Designation__c WHERE Discovery__c = :ParentDiscovery.Id ORDER BY LastModifiedDate ASC NULLS FIRST ]; } // See 'Controller Notes:' above public void DeleteDesignation() { // if for any reason we are missing the reference if (SelectedDeleteId == null) return; // find the record within the collection SE_Designation__c tobeDeleted = null; for(SE_Designation__c d : Designations) if (d.Id == SelectedDeleteId) { tobeDeleted = d; break; } //if record found delete it if (tobeDeleted != null) { delete tobeDeleted; } //refresh the data refreshDesignations(); } }
Visual Force Page
<apex:page showHeader="false" standardController="Discovery__c" extensions="DesignationEditorController"> <apex:form id="form" > <apex:pageBlock > <apex:pageBlockButtons > <apex:commandButton action="{!Save}" value="Save"/> <apex:commandButton action="{!Add}" value="New Designation"/> <!-- <apex:commandButton action="{!Add}" onclick="javascript:NewDesignation();" value="New Designation"/> --> </apex:pageBlockButtons> <apex:pageBlockTable value="{!Designations}" var="designation"> <apex:column > <a href="javascript:DeleteDesignation('{!designation.Id}');" style="font-weight:bold">Del</a> </apex:column> <apex:column headerValue="Rack"><apex:inputField value="{!designation.Dest_Position__c}"/></apex:column> <apex:column headerValue="Timeline"><apex:inputField value="{!designation.Dest_Time_Line__c}"/></apex:column> <apex:column headerValue="Prim Power Prod"><apex:inputField value="{!designation.Dest_Pri_Power_Prod_pick__c}"/></apex:column> <apex:column headerValue="Prim Power Recep"><apex:inputField value="{!designation.Dest_Pri_Receptacle__c}"/></apex:column> <apex:column headerValue="Redun Power Prod"><apex:inputField value="{!designation.Dest_Red_Power_Prod_pick__c}"/></apex:column> <apex:column headerValue="Redun Power Recep"><apex:inputField value="{!designation.Dest_Red_Receptacle__c}"/></apex:column> <apex:column headerValue="DC Product"><apex:inputField value="{!designation.Dest_DC_Product_pick__c}"/></apex:column> <apex:column headerValue="V Drop"><apex:inputField value="{!designation.Dest_V_Drop__c}"/></apex:column> <apex:column headerValue="DC Lug"><apex:inputField value="{!designation.Dest_DC_Lug__c}"/></apex:column> <apex:column headerValue="DC Term"><apex:inputField value="{!designation.Dest_DC_Term__c}"/></apex:column> <apex:column headerValue="Cab Size"><apex:inputField value="{!designation.Dest_Cabinet_Footprint__c}"/></apex:column> <apex:column headerValue="DEMARC"><apex:inputField value="{!designation.Dest_DEMARC__c}"/></apex:column> <apex:column headerValue="Weight"><apex:inputField value="{!designation.Dest_Weight__c}"/></apex:column> <apex:column headerValue="Cab Notes"><apex:inputField value="{!designation.Dest_Cab_Notes__c}"/></apex:column> </apex:pageBlockTable> </apex:pageBlock> <apex:actionFunction action="{!DeleteDesignation}" name="DeleteDesignation" reRender="form" > <apex:param name="accountid" value="" assignTo="{!SelectedDeleteId}"/> </apex:actionFunction> <apex:actionFunction action="{!Add}" name="NewDesignation" reRender="form" > </apex:actionFunction> </apex:form> </apex:page>
Test Code
@isTest(SeeAllData=false) private class DesignationEditorControllerTest { static testMethod void DesignationEditorControllerTestMethod() { // Prepare VF page PageReference pageRef = Page.SE_Designation_Section; Test.setCurrentPage(pageRef); // Get any Discovery and populate Controller Discovery__c d = new Discovery__c([Select Id From Discovery__c Limit 1]); ApexPages.StandardController sc = new ApexPages.StandardController(d); //list<Discovery__c> d = [Select Id From Discovery__c Limit 1]; //ApexPages.StandardController sc = new ApexPages.StandardController(d.get(0)); // Intialize controller DesignationEditorController controller = new DesignationEditorController(); // Add page parameters for required field ApexPages.currentPage().getParameters().put('Rack', 'Test Rack'); // Test methods controller.Add(); controller.Save(); controller.DeleteDesignation(); } }
Change the below code
DesignationEditorController controller = new DesignationEditorController();
to
DesignationEditorController controller = new DesignationEditorController(sc);
Please try this.
-Thanks
Ashlekh Gera
All Answers
Change the below code
DesignationEditorController controller = new DesignationEditorController();
to
DesignationEditorController controller = new DesignationEditorController(sc);
Please try this.
-Thanks
Ashlekh Gera
Here is the new attempt that fails too