You need to sign in to do that
Don't have an account?
SFDCDenver
Unable to get Controller Test to work
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
ERROR
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();
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>()
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();
}
}
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();
}
}
so I think the top few lines should be
try that instead.
All Answers
so I think the top few lines should be
try that instead.
Thank you
ApexPages.StandardController sc = new ApexPages.StandardController(d);
then sc could be passed as the argument.
i.e.
DesignationEditorController controller = new DesignationEditorController(sc);
So your
DesignationEditorController controller = new DesignationEditorController();
line will run the code in the constructor. That's how it's tested.
Ok passed execute, trying validation and will let you know. Thanks so much