• SFDCDenver
  • NEWBIE
  • 30 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 5
    Replies
Hello all,

I have a vf page with a hyperlink to delete the record in the list.  However, I cannot figure out how to test that portion of the code as if someone clicked it. I can into it but testing stops after this line "SE_Designation__c tobeDeleted = null;" and doesn't hit anything else.  

I cannot find any clear documentation on how to accomplish this.

Thanks everyone...

Here is the delete code in the controller.
// Cycle through records to locate record to be deleted (ID wrapper)
	public void DeleteDesignation() 
	{
		SE_Designation__c tobeDeleted = null;
		
		if (SelectedDeleteId != null) // Process if referenced
		{ 
			for(SE_Designation__c d : Designations) // find within the collection
			{
				if (d.Id == SelectedDeleteId)
				{
					tobeDeleted = d; // Flag record
					break;  // get out
				}
			}

			if (tobeDeleted != null){ 
				delete tobeDeleted; // delete if found
		
				refreshDesignations(); // refresh
			}
		}
	}

Here is the test code
 
static testMethod void DesignationEditorControllerTestMethod() {
    	// Prepare VF page
    	PageReference pageRef = Page.SE_Designation_Section;
		Test.setCurrentPage(pageRef);

		// Create a Discovery
        Discovery__c d = ([Select Id, Name From Discovery__c Limit 1]);

		// Populate and Intialize controller
		ApexPages.StandardController sc = new ApexPages.StandardController(d);
		DesignationEditorController controller = new DesignationEditorController(sc);

		// Test methods
		controller.Add();
		ApexPages.currentPage().getParameters().put('Rack', 'Test');
		controller.Save();
		controller.DeleteDesignation();
    }



 
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
 
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();

    }
}

 
Hi,
New to VF and I have a page that I am trying to test but I am not successful.  Need assistance as I don't understand why its getting that error.

Thank you.

TEST Code
  Test.startTest();
  PageReference pageRef = Page.SE_Designation_Section;
  Test.setCurrentPage(pageRef);
  ApexPages.CurrentPage().getParameters().put('Rack','Test Rack');
  DesignationEditorController controller = new DesignationEditorController();
  controller.Add();
  controller.Save();
  controller.DeleteDesignation();
  Test.stopTest();

ERROR
Compile error at line 5 column 44
Constructor not defined: [DesignationEditorController].<Constructor>()
 
VF CONTROLLER
public class DesignationEditorController {

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();

}

public void Add() {

doSave();

SE_Designation__c newDes = initNewDesignation();

insert newDes;

refreshDesignations();

}

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

];

}

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();

}

}
Hello all,

I have a vf page with a hyperlink to delete the record in the list.  However, I cannot figure out how to test that portion of the code as if someone clicked it. I can into it but testing stops after this line "SE_Designation__c tobeDeleted = null;" and doesn't hit anything else.  

I cannot find any clear documentation on how to accomplish this.

Thanks everyone...

Here is the delete code in the controller.
// Cycle through records to locate record to be deleted (ID wrapper)
	public void DeleteDesignation() 
	{
		SE_Designation__c tobeDeleted = null;
		
		if (SelectedDeleteId != null) // Process if referenced
		{ 
			for(SE_Designation__c d : Designations) // find within the collection
			{
				if (d.Id == SelectedDeleteId)
				{
					tobeDeleted = d; // Flag record
					break;  // get out
				}
			}

			if (tobeDeleted != null){ 
				delete tobeDeleted; // delete if found
		
				refreshDesignations(); // refresh
			}
		}
	}

Here is the test code
 
static testMethod void DesignationEditorControllerTestMethod() {
    	// Prepare VF page
    	PageReference pageRef = Page.SE_Designation_Section;
		Test.setCurrentPage(pageRef);

		// Create a Discovery
        Discovery__c d = ([Select Id, Name From Discovery__c Limit 1]);

		// Populate and Intialize controller
		ApexPages.StandardController sc = new ApexPages.StandardController(d);
		DesignationEditorController controller = new DesignationEditorController(sc);

		// Test methods
		controller.Add();
		ApexPages.currentPage().getParameters().put('Rack', 'Test');
		controller.Save();
		controller.DeleteDesignation();
    }



 
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
 
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();

    }
}

 
Hi,
New to VF and I have a page that I am trying to test but I am not successful.  Need assistance as I don't understand why its getting that error.

Thank you.

TEST Code
  Test.startTest();
  PageReference pageRef = Page.SE_Designation_Section;
  Test.setCurrentPage(pageRef);
  ApexPages.CurrentPage().getParameters().put('Rack','Test Rack');
  DesignationEditorController controller = new DesignationEditorController();
  controller.Add();
  controller.Save();
  controller.DeleteDesignation();
  Test.stopTest();

ERROR
Compile error at line 5 column 44
Constructor not defined: [DesignationEditorController].<Constructor>()
 
VF CONTROLLER
public class DesignationEditorController {

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();

}

public void Add() {

doSave();

SE_Designation__c newDes = initNewDesignation();

insert newDes;

refreshDesignations();

}

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

];

}

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();

}

}