function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Aparna Hegde 1Aparna Hegde 1 

Unknown constructor visualforce

Hi All,

I am getting an error Unknown constructor 'GetLawyers.GetLawyers()' for the below code. Could you please let me know what's causing this issue and how can i fix it?

VF Page:

<apex:page controller="GetLawyers" lightningStylesheets="true">  
    <apex:pageblock title="Available Lawyers">
    <apex:pageblocktable value="{!LawyersL3}" var ="Lawyer">
    <apex:column>
        <apex:facet name="header">Lawyer Name</apex:facet>
        <apex:outputText value="{!Lawyer.Lawyer__r.Name}"/>
                </apex:column>
    </apex:pageBlockTable> 
    </apex:pageblock>
</apex:page>


Apex Class:
public with sharing class GetLawyers {
    List<Lawyer_Data__c> LawyersL3 {get; set;}
              public GetLawyers(string PG, String State, String Skill, decimal ClientLat, decimal ClientLong, string classification){
      
       // Level 1 filtering
       set<Id> Filter1 = new set<Id>();
       List<User> LawyersL1 = new List<User>([select Id from user where Type__c='Lawyer']);
        system.debug('Result of Level 1 filtering'+ LawyersL1);
       for(User L:LawyersL1){
            Filter1.add(L.Id);
        }
        // Level 2 filtering
        set<Id> Filter2 = new set<Id>();
        set<Id> Filter3 = new set<Id>();
         set<Id> Filter4 = new set<Id>();
        List<Lawyer_Data__c> LawyersL2 =new List<Lawyer_Data__c>([select Id,Lawyer__c,SG_Office__c from Lawyer_Data__c where Practice_Group__c=:PG and State__c=:state and     
                                                       Injury_Classification__c INCLUDES(:classification) and Lawyer__c IN :Filter1]);
       system.debug('Result of Level 2 filtering'+ LawyersL2);
        for(Lawyer_Data__c LD:LawyersL2){
            Filter2.add(LD.Lawyer__c);
            Filter3.add(LD.SG_Office__c);
            Filter4.add(LD.Id);
        }
    
        // Distance Calculation
        Location ClientLocation = Location.newInstance(ClientLat,ClientLong);
        Map<Id, Double> DistanceTable = new Map<Id, Double>();
        List<SG_Office__c> Offices=new List<SG_Office__c>([select Id,name,Geolocation__Latitude__s,Geolocation__Longitude__s FROM SG_Office__c where Id IN:Filter3]);
           system.debug('Result of Distance Calculation'+ Offices);
        for(SG_Office__c SGO:Offices){
            Location SG_Office = Location.newInstance(SGO.Geolocation__Latitude__s, SGO.Geolocation__Longitude__s);
            Double Dist2ClientLoc = SG_Office.getDistance(ClientLocation, 'km');
            DistanceTable.put(SGO.Id,Dist2ClientLoc);
        }
       
        
                  for(Lawyer_Data__c LD1:LawyersL2){            
             LD1.distance__c = DistanceTable.get(LD1.SG_Office__c);  
                     }
        //update LawyersL2;
         system.debug('Display all the lawyers with distance'+LawyersL2);
        
        // Select the top 3 lawyers sorted by distance
             LawyersL3= [select Lawyer__r.Name, SG_Office__r.Name,Distance__c from Lawyer_Data__c where ID IN:Filter4 order by Distance__c];
        
            system.debug('Display all the lawyers sorted'+LawyersL3);
               
    }
      
}

Cheers,
Aparna
Best Answer chosen by Aparna Hegde 1
Ratnesh Kumar 6Ratnesh Kumar 6
Since you have overloaded constructor with parameters " public GetLawyers(string PG, String State, String Skill, decimal ClientLat, decimal ClientLong, string classification)", you need to write the default constructor with no parameter as well. Like public GetLawyers(){}.
This will resolve the issue.

All Answers

Ratnesh Kumar 6Ratnesh Kumar 6
Since you have overloaded constructor with parameters " public GetLawyers(string PG, String State, String Skill, decimal ClientLat, decimal ClientLong, string classification)", you need to write the default constructor with no parameter as well. Like public GetLawyers(){}.
This will resolve the issue.
This was selected as the best answer
Raj VakatiRaj Vakati
If you wanted to overload the constructor  you can try like below 
 
<apex:page controller="GetLawyers" lightningStylesheets="true">  
    <apex:pageblock title="Available Lawyers">
    <apex:pageblocktable value="{!LawyersL3}" var ="Lawyer">
    <apex:column>
        <apex:facet name="header">Lawyer Name</apex:facet>
        <apex:outputText value="{!Lawyer.Lawyer__r.Name}"/>
                </apex:column>
    </apex:pageBlockTable> 
    </apex:pageblock>
</apex:page>


public with sharing class GetLawyers {
    List<Lawyer_Data__c> LawyersL3 {get; set;}
	
	public GetLawyers(){
	GetLawyers(string PG, String State, String Skill, decimal ClientLat, decimal ClientLong, string classification) ;
	
	}
	
              public GetLawyers(string PG, String State, String Skill, decimal ClientLat, decimal ClientLong, string classification){
      
       // Level 1 filtering
       set<Id> Filter1 = new set<Id>();
       List<User> LawyersL1 = new List<User>([select Id from user where Type__c='Lawyer']);
        system.debug('Result of Level 1 filtering'+ LawyersL1);
       for(User L:LawyersL1){
            Filter1.add(L.Id);
        }
        // Level 2 filtering
        set<Id> Filter2 = new set<Id>();
        set<Id> Filter3 = new set<Id>();
         set<Id> Filter4 = new set<Id>();
        List<Lawyer_Data__c> LawyersL2 =new List<Lawyer_Data__c>([select Id,Lawyer__c,SG_Office__c from Lawyer_Data__c where Practice_Group__c=:PG and State__c=:state and     
                                                       Injury_Classification__c INCLUDES(:classification) and Lawyer__c IN :Filter1]);
       system.debug('Result of Level 2 filtering'+ LawyersL2);
        for(Lawyer_Data__c LD:LawyersL2){
            Filter2.add(LD.Lawyer__c);
            Filter3.add(LD.SG_Office__c);
            Filter4.add(LD.Id);
        }
    
        // Distance Calculation
        Location ClientLocation = Location.newInstance(ClientLat,ClientLong);
        Map<Id, Double> DistanceTable = new Map<Id, Double>();
        List<SG_Office__c> Offices=new List<SG_Office__c>([select Id,name,Geolocation__Latitude__s,Geolocation__Longitude__s FROM SG_Office__c where Id IN:Filter3]);
           system.debug('Result of Distance Calculation'+ Offices);
        for(SG_Office__c SGO:Offices){
            Location SG_Office = Location.newInstance(SGO.Geolocation__Latitude__s, SGO.Geolocation__Longitude__s);
            Double Dist2ClientLoc = SG_Office.getDistance(ClientLocation, 'km');
            DistanceTable.put(SGO.Id,Dist2ClientLoc);
        }
       
        
                  for(Lawyer_Data__c LD1:LawyersL2){            
             LD1.distance__c = DistanceTable.get(LD1.SG_Office__c);  
                     }
        //update LawyersL2;
         system.debug('Display all the lawyers with distance'+LawyersL2);
        
        // Select the top 3 lawyers sorted by distance
             LawyersL3= [select Lawyer__r.Name, SG_Office__r.Name,Distance__c from Lawyer_Data__c where ID IN:Filter4 order by Distance__c];
        
            system.debug('Display all the lawyers sorted'+LawyersL3);
               
    }
      
}

 
Aparna Hegde 1Aparna Hegde 1
Thank you all. The issue is resolved.