You need to sign in to do that
Don't have an account?
Juan Pablo Escobar
Error: Compile Error: Constructor not defined
I'm new to Visualforce and I want to create a unit test to test my page but I'm getting an error. Help will be really apreciated!
Thanks
Pablo
.....
Apex Class:
public with sharing class UnqulifiedLeads
{
public ApexPages.StandardSetController setCon;
public UnqulifiedLeads(ApexPages.StandardSetController Ld){
this.setCon= Ld;
}
public String selectedValue { get; set; }
public Boolean UseCustomReasons { get; set; }
public List<SelectOption> getMyOptions(){
List<SelectOption> options = new List<SelectOption>();
// Reading picklist values and labels
Schema.DescribeFieldResult fieldResult = Lead.Unqualified_Reason__c.getDescribe();
List<Schema.PicklistEntry> picklistEntries = fieldResult.getPicklistValues();
// Adding apicklist values to the select list
options.add(new SelectOption('N/A','N/A'));
options.add(new SelectOption('Custom','Custom for each Lead'));
for(Schema.PicklistEntry entry : picklistEntries){
options.add(new SelectOption(entry.getValue(), entry.getLabel()));
}
return options;
}
public PageReference bumpLeads(){
List<Lead> selectedLeads = (List<Lead>) setCon.getSelected();
if(test.isrunningTest()){
selectedLeads = [
SELECT
Id, Status, Firstname, Lastname,Unqualified_Reason__c
FROM
Lead
ORDER BY
createddate DESC
LIMIT 1
];
selectedValue = 'N/A';
}
// Update records
for(Lead selectedlead : selectedLeads)
{
selectedlead.Status = 'Unqualified';
system.debug('selectedValue' + selectedValue);
if(selectedValue == 'N/A' || selectedValue == '' )
selectedlead.Unqualified_Reason__c = 'Budget';
else
if(selectedValue != 'Custom')
selectedlead.Unqualified_Reason__c = selectedValue;
}
updateLeads();
return null;
}
public PageReference updateLeads()
{
// Call StandardSetController 'save' method to update
return setCon.save();
}
}
................................................
Visualforce page
<apex:page standardController="Lead" extensions="UnqulifiedLeads" recordSetVar="leads" >
<apex:form >
<apex:pageBlock title="Bump Selected Leads">
<apex:outputLabel>Set Unqualify Reason for Leads </apex:outputLabel>
<apex:selectList label="hola" value="{!selectedValue}" size="1" multiselect="false">
<apex:selectOptions value="{!MyOptions}"/>
</apex:selectList>
<apex:pageBlockButtons >
<apex:commandButton action="{!bumpLeads}" value="Confirm" id="Confirm"/>
</apex:pageBlockButtons><br/><br/>
<apex:pageBlockTable value="{!selected}" var="lead">
<apex:column value="{!lead.FirstName}"/>
<apex:column value="{!lead.LastName}"/>
<apex:column value="{!lead.status}"/>
<apex:column headerValue="Reason">
<apex:actionRegion >
<apex:outputField value="{!lead.Unqualified_Reason__c}">
<apex:inlineEditSupport event="ondblClick" showOnEdit="Confirm" />
</apex:outputField>
</apex:actionRegion>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
......
Unit Test
@isTest
public class UnqulifiedLeadsTest{
public static testMethod void testUnqulifiedLeads() {
//Create Test leads
List<Lead> leadList= new List<Lead>();
Lead leadTest1 = new Lead();
leadTest1.FirstName = 'Fisrtname1';
leadTest1.LastName = 'Lastname1';
leadTest1.Lead_Source_custom_field__c= 'Unknown';
leadTest1.Status= '1 - Open Lead';
Lead leadTest2 = new Lead();
leadTest2.FirstName = 'Fisrtname2';
leadTest2.LastName = 'Lastname2';
leadTest2.Lead_Source_custom_field__c= 'Unknown';
leadTest2.Status= '1 - Open Lead';
leadList.add(leadTest1);
leadList.add(leadTest2);
insert leadList;
Test.startTest();
// load the page
PageReference pageRef = Page.MassUnqulifyLeads;
Test.setCurrentPageReference(pageRef);
ApexPages.StandardController sc = new ApexPages.StandardController(leadTest1);
UnqulifiedLeads leadsTest = new UnqulifiedLeads(sc);
Test.stopTest();
}
}
Error Message: Error: Compile Error: Constructor not defined: [UnqulifiedLeads].<Constructor>(ApexPages.StandardController) at line 28 column 33
Thanks
Pablo
.....
Apex Class:
public with sharing class UnqulifiedLeads
{
public ApexPages.StandardSetController setCon;
public UnqulifiedLeads(ApexPages.StandardSetController Ld){
this.setCon= Ld;
}
public String selectedValue { get; set; }
public Boolean UseCustomReasons { get; set; }
public List<SelectOption> getMyOptions(){
List<SelectOption> options = new List<SelectOption>();
// Reading picklist values and labels
Schema.DescribeFieldResult fieldResult = Lead.Unqualified_Reason__c.getDescribe();
List<Schema.PicklistEntry> picklistEntries = fieldResult.getPicklistValues();
// Adding apicklist values to the select list
options.add(new SelectOption('N/A','N/A'));
options.add(new SelectOption('Custom','Custom for each Lead'));
for(Schema.PicklistEntry entry : picklistEntries){
options.add(new SelectOption(entry.getValue(), entry.getLabel()));
}
return options;
}
public PageReference bumpLeads(){
List<Lead> selectedLeads = (List<Lead>) setCon.getSelected();
if(test.isrunningTest()){
selectedLeads = [
SELECT
Id, Status, Firstname, Lastname,Unqualified_Reason__c
FROM
Lead
ORDER BY
createddate DESC
LIMIT 1
];
selectedValue = 'N/A';
}
// Update records
for(Lead selectedlead : selectedLeads)
{
selectedlead.Status = 'Unqualified';
system.debug('selectedValue' + selectedValue);
if(selectedValue == 'N/A' || selectedValue == '' )
selectedlead.Unqualified_Reason__c = 'Budget';
else
if(selectedValue != 'Custom')
selectedlead.Unqualified_Reason__c = selectedValue;
}
updateLeads();
return null;
}
public PageReference updateLeads()
{
// Call StandardSetController 'save' method to update
return setCon.save();
}
}
................................................
Visualforce page
<apex:page standardController="Lead" extensions="UnqulifiedLeads" recordSetVar="leads" >
<apex:form >
<apex:pageBlock title="Bump Selected Leads">
<apex:outputLabel>Set Unqualify Reason for Leads </apex:outputLabel>
<apex:selectList label="hola" value="{!selectedValue}" size="1" multiselect="false">
<apex:selectOptions value="{!MyOptions}"/>
</apex:selectList>
<apex:pageBlockButtons >
<apex:commandButton action="{!bumpLeads}" value="Confirm" id="Confirm"/>
</apex:pageBlockButtons><br/><br/>
<apex:pageBlockTable value="{!selected}" var="lead">
<apex:column value="{!lead.FirstName}"/>
<apex:column value="{!lead.LastName}"/>
<apex:column value="{!lead.status}"/>
<apex:column headerValue="Reason">
<apex:actionRegion >
<apex:outputField value="{!lead.Unqualified_Reason__c}">
<apex:inlineEditSupport event="ondblClick" showOnEdit="Confirm" />
</apex:outputField>
</apex:actionRegion>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
......
Unit Test
@isTest
public class UnqulifiedLeadsTest{
public static testMethod void testUnqulifiedLeads() {
//Create Test leads
List<Lead> leadList= new List<Lead>();
Lead leadTest1 = new Lead();
leadTest1.FirstName = 'Fisrtname1';
leadTest1.LastName = 'Lastname1';
leadTest1.Lead_Source_custom_field__c= 'Unknown';
leadTest1.Status= '1 - Open Lead';
Lead leadTest2 = new Lead();
leadTest2.FirstName = 'Fisrtname2';
leadTest2.LastName = 'Lastname2';
leadTest2.Lead_Source_custom_field__c= 'Unknown';
leadTest2.Status= '1 - Open Lead';
leadList.add(leadTest1);
leadList.add(leadTest2);
insert leadList;
Test.startTest();
// load the page
PageReference pageRef = Page.MassUnqulifyLeads;
Test.setCurrentPageReference(pageRef);
ApexPages.StandardController sc = new ApexPages.StandardController(leadTest1);
UnqulifiedLeads leadsTest = new UnqulifiedLeads(sc);
Test.stopTest();
}
}
Error Message: Error: Compile Error: Constructor not defined: [UnqulifiedLeads].<Constructor>(ApexPages.StandardController) at line 28 column 33
ApexPages.StandardSetController stdSetController = new ApexPages.StandardSetController(leadList);
stdSetController.setSelected(leadList);
UnqulifiedLeads ext = new UnqulifiedLeads(stdSetController);
Try to update your code like below
Let us know if this will help you
All Answers
ApexPages.StandardSetController stdSetController = new ApexPages.StandardSetController(leadList);
stdSetController.setSelected(leadList);
UnqulifiedLeads ext = new UnqulifiedLeads(stdSetController);
Try to update your code like below
Let us know if this will help you