You need to sign in to do that
Don't have an account?
A Raj 9
constructor not defined error for a test class to a button
Hi All, Plz help me out. This is the test class code for a button to delete all the sub object records. while saving it is giving error as "Constructor not defined: [PhaseDeleteAllLinesExt].<Constructor>(ApexPages.StandardController)"
below is the test class
******
@isTest
public class PhaseDeleteAllLinesExtTest {
static testMethod void MyTest()
{
list<opportunity> opp = [select id, name from opportunity where id='0060h000010bfWz'];
Project_Phase_Plan__c plan = new Project_Phase_Plan__c ();
plan.Phase_Plan_Description__c = 'Testing';
insert plan;
Project_Phase__c phase = new Project_Phase__c();
phase.Project_Phase__c = 1;
phase.Trade__c = 'Glazier';
insert phase ;
PageReference pageRef = Page.ProjectPhaseDeleteAllLines;
// VF Page name is 'ProjectPhaseDeleteAllLines'.
pageRef.getparameters().put('Id', plan.id);
Test.setCurrentPage(pageRef);
Apexpages.StandardController sc = new Apexpages.StandardController(plan);
PhaseDeleteAllLinesExt ext = new PhaseDeleteAllLinesExt(sc);
ext.deleteAllLines();
ext.close();
}
static testMethod void MyTest2()
{
Project_Phase__c phase = new Project_Phase__c();
phase.Project_Phase__c=1;
insert phase ;
Project_Phase_Plan__c plan = new Project_Phase_Plan__c ();
plan.Phase_Plan_Description__c = 'Testing';
insert plan;
PageReference pageRef = Page.ProjectPhaseDeleteAllLines;
// VF Page name is 'ProjectPhaseDeleteAllLines'.
Test.setCurrentPage(pageRef);
Apexpages.StandardController sc = new Apexpages.StandardController(plan);
PhaseDeleteAllLinesExt ext = new PhaseDeleteAllLinesExt(sc);
ext.deleteAllLines();
ext.close();
}
}
below is the test class
******
@isTest
public class PhaseDeleteAllLinesExtTest {
static testMethod void MyTest()
{
list<opportunity> opp = [select id, name from opportunity where id='0060h000010bfWz'];
Project_Phase_Plan__c plan = new Project_Phase_Plan__c ();
plan.Phase_Plan_Description__c = 'Testing';
insert plan;
Project_Phase__c phase = new Project_Phase__c();
phase.Project_Phase__c = 1;
phase.Trade__c = 'Glazier';
insert phase ;
PageReference pageRef = Page.ProjectPhaseDeleteAllLines;
// VF Page name is 'ProjectPhaseDeleteAllLines'.
pageRef.getparameters().put('Id', plan.id);
Test.setCurrentPage(pageRef);
Apexpages.StandardController sc = new Apexpages.StandardController(plan);
PhaseDeleteAllLinesExt ext = new PhaseDeleteAllLinesExt(sc);
ext.deleteAllLines();
ext.close();
}
static testMethod void MyTest2()
{
Project_Phase__c phase = new Project_Phase__c();
phase.Project_Phase__c=1;
insert phase ;
Project_Phase_Plan__c plan = new Project_Phase_Plan__c ();
plan.Phase_Plan_Description__c = 'Testing';
insert plan;
PageReference pageRef = Page.ProjectPhaseDeleteAllLines;
// VF Page name is 'ProjectPhaseDeleteAllLines'.
Test.setCurrentPage(pageRef);
Apexpages.StandardController sc = new Apexpages.StandardController(plan);
PhaseDeleteAllLinesExt ext = new PhaseDeleteAllLinesExt(sc);
ext.deleteAllLines();
ext.close();
}
}
Please share your class code as well.
***********
public class PhaseDeleteAllLinesExt
{
public Project_Phase_Plan__c pplan{get;set;}
public String deleteWarning{get;set;}
public Boolean deleteOK{get;set;}
public Boolean showCancel{get;set;}
public Boolean showClose{get;set;}
public Set<String> deleteAllOK = new Set<String> {'Draft', 'Pre-Release Review', 'Confirmation Pending', 'Confirmed'};
public PageReference currentPage = ApexPages.currentPage();
public PhaseDeleteAllLinesExt(ApexPages.StandardSetController stdSetController)
{
//
// Get the Order Release Information
//
deleteOK = false;
showCancel = true;
showClose = false;
Id id = ApexPages.CurrentPage().getParameters().get('id');
if (id != null)
{
System.debug('OER ID = ' + String.valueOf(id));
pplan = [SELECT Id, Name FROM Project_Phase_Plan__c WHERE Id = :id LIMIT 1];
}
if (pplan == null)
{
ApexPages.Message noOEError = new ApexPages.Message(ApexPages.Severity.ERROR,'** ERROR - Unable to retrieve the Project Phase Plan Information');
ApexPages.addMessage(noOEError);
showClose = true;
showCancel = false;
}
else
{
deleteWarning = 'WARNING: You have requested the deletion of all Project Phase for Project Phase Plan ' + pplan.Name + '<br>'+
'Click the Continue button to confirm deletion; click the Cancel button to return to the OProject Phase Plan Without deleting the Lines';
deleteOK = true;
}
}
public PageReference close()
{
return new PageReference('javascript:window.self.close()');
}
public PageReference deleteAllLines()
{
List<Database.DeleteResult> drList = new List<Database.DeleteResult>();
Boolean hasErrors = false;
List<Project_Phase__c> linesToDelete = [SELECT Id, Project_Phase_Plan__c FROM Project_Phase__c WHERE Project_Phase_Plan__c = :pplan.Id];
if (linesToDelete.size() > 0)
{
ApexPages.Message databaseErrorMsg;
drList = Database.delete(linesToDelete, true);
Integer i = 0;
for(Database.DeleteResult dr : drList)
{
if (!dr.isSuccess())
{
hasErrors = true;
for(Database.Error err : dr.getErrors())
{
databaseErrorMsg = new ApexPages.Message(ApexPages.Severity.ERROR, '*** An error occurred deleting Project Phase ID ' +
String.valueOf(linesToDelete[i].id) + '; ' + err.getMessage());
ApexPages.addMessage(databaseErrorMsg);
}
}
i++;
}
}
if (hasErrors)
{
deleteWarning = 'Errors occurred while trying to delete the Project Phases; click the Cancel button to return to the Order Entry Release Page';
}
else
{
deleteWarning = String.valueOf(linesToDelete.size()) + ' Project Phase were successfully deleted.<br>' +
'Close this window and then refresh the Project Phase Plan page to see the results';
}
deleteOK = false;
showClose = true;
showCancel = false;
return currentPage;
}
}
****
You are using StandardSetController so you need to pass the list of Project_Phase_Plan__c like
ApexPages.StandardSetController stdSetController = newApexPages.StandardSetController(lst of Project Phase Plan);
PhaseDeleteAllLinesExt ext = new PhaseDeleteAllLinesExt(stdSetController );
Let me know if it will work for you.
********
list<Project_Phase_Plan__c> newplan = new list<Project_Phase_Plan__c>([select Id, name from Project_Phase_Plan__c]);
PageReference pageRef = Page.ProjectPhaseDeleteAllLines;
pageRef.getparameters().put('Id', plan.Id);
Test.setCurrentPage(pageRef);
Apexpages.StandardController sc = new Apexpages.StandardController(plan);
PhaseDeleteAllLinesExt ext = new PhaseDeleteAllLinesExt(sc); //getting error here in this line
ext.deleteAllLines();
ext.close();
********
Instead of using Apexpages.StandardController please use ApexPages.StandardSetController.
'Class.PhaseDeleteAllLinesExt.deleteAllLines: line 52, column 1'
'Class.PhaseDeleteAllLinesExtTest.MyTest2: line 61, column 1'
'System.NullPointerException: Attempt to de-reference a null object'
and at line 52 we have class code as
**************
public class PhaseDeleteAllLinesExt
{
public Project_Phase_Plan__c pplan{get;set;}
public String deleteWarning{get;set;}
public Boolean deleteOK{get;set;}
public Boolean showCancel{get;set;}
public Boolean showClose{get;set;}
public Set<String> deleteAllOK = new Set<String> {'Draft', 'Pre-Release Review', 'Confirmation Pending', 'Confirmed'};
public PageReference currentPage = ApexPages.currentPage();
public PhaseDeleteAllLinesExt(ApexPages.StandardSetController stdSetController)
{
//
// Get the Order Release Information
//
deleteOK = false;
showCancel = true;
showClose = false;
Id id = ApexPages.CurrentPage().getParameters().get('id');
if (id != null)
{
System.debug('OER ID = ' + String.valueOf(id));
pplan = [SELECT Id, Name FROM Project_Phase_Plan__c WHERE Id = :id LIMIT 1];
}
if (pplan == null)
{
ApexPages.Message noOEError = new ApexPages.Message(ApexPages.Severity.ERROR,'** ERROR - Unable to retrieve the Project Phase Plan Information');
ApexPages.addMessage(noOEError);
showClose = true;
showCancel = false;
}
else
{
deleteWarning = 'WARNING: You have requested the deletion of all Project Phase for Project Phase Plan ' + pplan.Name + '<br>'+
'Click the Continue button to confirm deletion; click the Cancel button to return to the OProject Phase Plan Without deleting the Lines';
deleteOK = true;
}
}
public PageReference close()
{
return new PageReference('javascript:window.self.close()');
}
public PageReference deleteAllLines()
{
List<Database.DeleteResult> drList = new List<Database.DeleteResult>();
Boolean hasErrors = false;
List<Project_Phase__c> linesToDelete = [SELECT Id, Project_Phase_Plan__c FROM Project_Phase__c WHERE Project_Phase_Plan__c = :pplan.Id]; //this is LINE 52 ERROR
if (linesToDelete.size() > 0)
{
ApexPages.Message databaseErrorMsg;
drList = Database.delete(linesToDelete, true);
Integer i = 0;
for(Database.DeleteResult dr : drList)
{
if (!dr.isSuccess())
{
hasErrors = true;
for(Database.Error err : dr.getErrors())
{
databaseErrorMsg = new ApexPages.Message(ApexPages.Severity.ERROR, '*** An error occurred deleting Project Phase ID ' +
String.valueOf(linesToDelete[i].id) + '; ' + err.getMessage());
ApexPages.addMessage(databaseErrorMsg);
}
}
i++;
}
}
if (hasErrors)
{
deleteWarning = 'Errors occurred while trying to delete the Project Phases; click the Cancel button to return to the Order Entry Release Page';
}
else
{
deleteWarning = String.valueOf(linesToDelete.size()) + ' Project Phase were successfully deleted.<br>' +
'Close this window and then refresh the Project Phase Plan page to see the results';
}
deleteOK = false;
showClose = true;
showCancel = false;
return currentPage;
}
}
***************
and at line 61 code is from test class and below is the code
************
@isTest
public class PhaseDeleteAllLinesExtTest {
static testMethod void MyTest()
{
// list<opportunity> opp = [select id, name from opportunity where id='0060h000010bfWz'];
Project_Phase_Plan__c plan = new Project_Phase_Plan__c ();
plan.Phase_Plan_Description__c = 'Testing';
//add other fields here
insert plan;
Project_Phase__c phase = new Project_Phase__c();
phase.Project_Phase_Plan__c = plan.Id;
phase.Project_Phase__c = 1;
phase.Trade__c = 'Glazier';
//add other fields here
insert phase ;
list<Project_Phase_Plan__c> newplan = new list<Project_Phase_Plan__c>([select Id, name, Phase_Plan_Description__c from Project_Phase_Plan__c]);
PageReference pageRef = Page.ProjectPhaseDeleteAllLines;
pageRef.getparameters().put('Id', plan.Id);
Test.setCurrentPage(pageRef);
ApexPages.StandardSetController sc = new ApexPages.StandardSetController(newplan);
PhaseDeleteAllLinesExt ext = new PhaseDeleteAllLinesExt(sc);
ext.deleteAllLines();
ext.close();
}
static testMethod void MyTest2()
{
Project_Phase_Plan__c plan = new Project_Phase_Plan__c ();
plan.Phase_Plan_Description__c = 'Testing';
//plan.Name ='Test';
//add other fields
insert plan;
Project_Phase__c phase = new Project_Phase__c();
phase.Project_Phase_Plan__c = plan.Id;
phase.Project_Phase__c = 1;
phase.Trade__c = 'Glazier';
//phase.Name = 'Test' ;
//add other fields
insert phase ;
list<Project_Phase_Plan__c> newplan = new list<Project_Phase_Plan__c>([select Id, name, Phase_Plan_Description__c from Project_Phase_Plan__c]);
PageReference pageRef = Page.ProjectPhaseDeleteAllLines;
Test.setCurrentPage(pageRef);
ApexPages.StandardSetController sc = new ApexPages.StandardSetController(newplan);
PhaseDeleteAllLinesExt ext = new PhaseDeleteAllLinesExt(sc);
ext.deleteAllLines();
ext.close();
}
}
*******************