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
Michael Hedrick 2Michael Hedrick 2 

Unknown Constructor error in VF Page

Hello everyone;
I thought I had this right but I am not refencing the Class correctly in my VF page. What I am trying to do is show a list of  accoutns around a lead record based on the geo location.
error: Error: Unknown constructor 'LeadGeoController.LeadGeoController(ApexPages.StandardController controller)
<apex:page standardstylesheets="true" showheader="false" standardController="Lead" extensions="LeadGeoController">

       <apex:pageBlock title="Recent Orders for Lead">
          <apex:pageBlockTable styleClass="responsive-table" value="{!GetAccountsNearLead}" var="accounts">
             <apex:column title="Account Name " value="{!account.name}" headerValue="Name"/>
             <apex:column title="Contacts Email Address " value="{!account.Primary_Contact_Email_Address__c}" headerValue="Email Address"/>   
             <apex:column title="Account Street Address " value="{!account.BillingStreet}" headerValue="Address"/>
             <apex:column title="Account City " value="{!account.BillingCity}" headerValue="City"/>
             <apex:column title="Diectance From Lead " value="{!account.Distance}" headerValue="Distance"/>
          </apex:pageBlockTable>   
    </apex:pageBlock>
</apex:page>
 
public with sharing class LeadGeoController {

     
     public Decimal lat { get; set; }
     public Decimal longitude{ get; set; } 

     public LeadGeoController () 
     {
     List<Lead> lat =  [SELECT MALatitude__c from Lead WHERE Id=:ApexPages.currentPage().getParameters().get('id')];
       List<Lead> longituide= [SELECT MALongitude__c from Lead WHERE Id=:ApexPages.currentPage().getParameters().get('id')];
    }
     
      
    public List<Account> GetAccountsNearLead() {
        return [SELECT Name, Primary_Contact_Email_Address__c,BillingStreet,BillingCity,distance(BillingAddress, geolocation(:lat , :longitude), 'mi')  Distance
            FROM Account
            WHERE Partner_Type__c= 'TrexPro' AND
            distance(BillingAddress, geolocation(:lat , :longitude), 'mi') < 10 
        //    AND Id = :ApexPages.currentPage().getParameters().get('id')
            ORDER BY distance(BillingAddress, geolocation(:lat , :longitude), 'mi')
            LIMIT 5];            
        }
      
    }
Thanks,
M
 
Raj VakatiRaj Vakati
Your construct should be like this 
public LeadGeoController (ApexPages.StandardController stdController) 

When you use StandardController you need to pass ApexPages.StandardController as an arg to the constructor . 
 
Michael Hedrick 2Michael Hedrick 2
Thansk Raj,
I totally forgot that piece.
So now I get this error on the Vf page:
Error: Unknown property 'LeadStandardController.GetAccountsNearLead'
<apex:page standardstylesheets="true" showheader="false" standardController="Lead" extensions="LeadGeoController">

       <apex:pageBlock title="Recent Orders for Lead">
          <apex:pageBlockTable styleClass="responsive-table" value="{!GetAccountsNearLead}" var="accounts">
             <apex:column title="Account Name " value="{!account.name}" headerValue="Name"/>
             <apex:column title="Contacts Email Address " value="{!account.Primary_Contact_Email_Address__c}" headerValue="Email Address"/>   
             <apex:column title="Account Street Address " value="{!account.BillingStreet}" headerValue="Address"/>
             <apex:column title="Account City " value="{!account.BillingCity}" headerValue="City"/>
             <apex:column title="Diectance From Lead " value="{!account.Distance}" headerValue="Distance"/>
          </apex:pageBlockTable>   
    </apex:pageBlock>
</apex:page>
 
public with sharing class LeadGeoController {
     List<Account> GetAccountsNearLead;
     Account Acct;
     public Decimal lat { get; set; }
     public Decimal longitude{ get; set; } 

     public LeadGeoController (ApexPages.StandardController stdController) {}    

  
     {
     List<Lead> lat =  [SELECT MALatitude__c from Lead WHERE Id=:ApexPages.currentPage().getParameters().get('id')];
     List<Lead> longituide= [SELECT MALongitude__c from Lead WHERE Id=:ApexPages.currentPage().getParameters().get('id')];
    }
     
      
      public Account GetAccountsNearLead() {
        if (Acct== null) {
          Acct= [SELECT Name,distance(BillingAddress, geolocation(:lat , :longitude), 'mi')  Distance, Primary_Contact_Email_Address__c,BillingStreet,BillingCity
            FROM Account
            WHERE Partner_Type__c= 'TrexPro' AND
            distance(BillingAddress, geolocation(:lat , :longitude), 'mi') < 10 
        //    AND Id = :ApexPages.currentPage().getParameters().get('id')
            ORDER BY distance(BillingAddress, geolocation(:lat , :longitude), 'mi')
            LIMIT 5];            
        }
        return Acct;
    }
    
   }
Thanks for all of your help.

 
Shubham saini 14Shubham saini 14

Hello,

 

You should use <apex:repeat > to iterate list of account, Here the code

 

<apex:page standardstylesheets="true" showheader="false" standardController="Lead" extensions="LeadGeoController">

       <apex:pageBlock title="Recent Orders for Lead">
          <apex:pageBlockTable styleClass="responsive-table">
             <apex:repeat value="{!GetAccountsNearLead}" var="accounts">
             <apex:column title="Account Name " value="{!account.name}" headerValue="Name"/>
             <apex:column title="Contacts Email Address " value="{!account.Primary_Contact_Email_Address__c}" headerValue="Email Address"/>   
             <apex:column title="Account Street Address " value="{!account.BillingStreet}" headerValue="Address"/>
             <apex:column title="Account City " value="{!account.BillingCity}" headerValue="City"/>
             <apex:column title="Diectance From Lead " value="{!account.Distance}" headerValue="Distance"/>
             </apex:repeat>
          </apex:pageBlockTable>   
    </apex:pageBlock>
</apex:page>

Thank you
Michael Hedrick 2Michael Hedrick 2
Thanks Shubham,
I am getting the follow error:
Missing required attribute value in <apex:pageBlockTable> in LeadGeoController 
Do I need to remove the pageBlockTable?  Do the Apexd Class also need to be edited?
Thank you for your time.
M
Shubham saini 14Shubham saini 14
Hi Michael,
 
<apex:page standardstylesheets="true" showheader="false" standardController="Lead" extensions="LeadGeoController">

       <apex:pageBlock title="Recent Orders for Lead">
         //use AccountsNearLead to call GetAccountsNearLead function
          <apex:pageBlockTable styleClass="responsive-table" value="{!AccountsNearLead}" var="account">
             <apex:column title="Account Name " value="{!account.name}" headerValue="Name"/>
             <apex:column title="Contacts Email Address " value="{!account.Primary_Contact_Email_Address__c}" headerValue="Email Address"/>   
             <apex:column title="Account Street Address " value="{!account.BillingStreet}" headerValue="Address"/>
             <apex:column title="Account City " value="{!account.BillingCity}" headerValue="City"/>
             <apex:column title="Diectance From Lead " value="{!account.Distance}" headerValue="Distance"/>
          </apex:pageBlockTable>   
    </apex:pageBlock>
</apex:page>


I hope , it will help you

Thank you
 

Michael Hedrick 2Michael Hedrick 2
Hey Shubham,
Very close.  The VF page does not recognize 'Distance' as a SObject field.     
Shubham saini 14Shubham saini 14
I think, you are using custom field Distance.so use API name of that field

 
<apex:column title="Diectance From Lead " value="{!account.Distance__c}"


 
Michael Hedrick 2Michael Hedrick 2
Hey Shubham,
The distance value is part of the Geolocation function and does not exist in Salesforce as a field.
Thanks,
M
Michael Hedrick 2Michael Hedrick 2
I am getting a 'List has no rows for assignment to SObject ' when I call the VF page from a custom button.
Even If I hardcode the Lat and Long:
lat = 39.14 ;
longitude = -78.17 

Is the SOQL statement not pulling in the Lat and Long values?

Thanks