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 8Aparna Hegde 8 

I am trying to run this on developer console - execute anonymous. Getting error

public without sharing class LawyerAddressAllocationSelector {

    public Map< Lawyer_Address_Allocation__c,String> selectByClosest(List<Id> lawyerIds, Double latitude, Double longitude) {
         Map< Lawyer_Address_Allocation__c,String>  DistWithAddr = new Map< Lawyer_Address_Allocation__c,String>();  
    for (Lawyer_Address_Allocation__c record:[Select Id,Start_Time__c, End_Time__c, Lawyer_Name__c, Lawyer_Name__r.Name,
                Office_Address__c, Office_Address__r.Geo_Coordinate__c,DISTANCE(Office_Address__r.Geo_Coordinate__c, GEOLOCATION(:latitude, :longitude), 'km') Dist
            From Lawyer_Address_Allocation__c
            Where (
                (Start_Time__c = null And End_Time__c = null)
                Or (Start_Time__c !=null And End_Time__c != null And End_Time__c >= TODAY)
            ) And Office_Address__c!=null AND Lawyer_Name__c in: lawyerIds
            Order by DISTANCE(Office_Address__r.Geo_Coordinate__c, GEOLOCATION(:latitude, :longitude), 'km'), Primary__c
            Limit 10000
                                             ]){
                                                 DistWithAddr.put(record,(String)record.get('Dist'));
    system.debug('Return'+ DistWithAddr) ;                                        }
    return DistWithAddr;
    }


List<Id> Lid=new List<Id>();
Lid.add('a0iO000000AUAESIA5');
Lid.add('a0iO000000AeLcAIAV');
LawyerAddressAllocationSelector.selectByClosest(Lid,-37.908700,144.741720);

Line: 4, Column: 33
Method does not exist or incorrect signature: void selectByClosest(List<Id>, Decimal, Decimal) from the type LawyerAddressAllocationSelector
Sunil RathoreSunil Rathore
Hi Aparna,

Greetings to you!!!

Your selectByClosest  method is not a static method so you cannot call this method directly with the class name.

You have to make a instance of your class and then call you method. 

Please refer this:
LawyerAddressAllocationSelector objClass = new LawyerAddressAllocationSelector();

objClass.selectByClosest(Lid,-37.908700,144.741720);
Please refer this link for more details:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_static.htm

Hope this will help you. If does then mark it as the best answer so it can also help others in the future.


Many Thanks,
Sunil Rathore