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
Harpreet Kaur 45Harpreet Kaur 45 

Getting Error when deploying to production, Address field does not exist on lead. I am using Address in Distance() in SOQL in apex class

global with sharing class LeadsNearbyMe {
          public static List<Lead> result;
@RemoteAction
   global static List<Lead> getNearby(String lat, String lon) {
    
     Location loc1 = Location.newInstance(Decimal.Valueof(lat),Decimal.Valueof(lon));
      
     result=[SELECT Id, Name, Longitude, Latitude, Street, City,State,Country, PostalCode FROM Lead WHERE DISTANCE(Address,:loc1, 'km') < 60 ORDER BY DISTANCE(Address, :loc1, 'km') LIMIT 10];
   
       return result;
    }

}
Abdul KhatriAbdul Khatri
I don't see any issue here, can you please check api in Production to see if it is supported.
Harpreet Kaur 45Harpreet Kaur 45
Hi Abdul, how exactlt I can check that, I generated AI WSDL and it gave me this on Lead , production is using 42.0 version.

<complexType name="Lead">
<complexContent>
<extension base="ens:sObject">
<sequence>
<element name="AcceptedEventRelations" nillable="true" minOccurs="0" type="tns:QueryResult"/>
<element name="Account_Number__c" nillable="true" minOccurs="0" type="xsd:double"/>
<element name="ActivityHistories" nillable="true" minOccurs="0" type="tns:QueryResult"/>
<element name="Address" nillable="true" minOccurs="0" type="tns:address"/>
<element name="Administrator_Email__c" nillable="true" minOccurs="0" type="xsd:string"/> 
Harpreet Kaur 45Harpreet Kaur 45
This is the error I am getting on deploy
line 12, column 13: 'km') < 60 ORDER BY DISTANCE(Address, :loc1, 'km') LIMIT 10 ^ ERROR at Row:1:Column:147 No such column 'Address' on entity 'Lead'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. 
Stack Trace: null
Abdul KhatriAbdul Khatri
strange, Can you try using individual fields like Street etc.
Harpreet Kaur 45Harpreet Kaur 45
how can i use street, city in DISTANCE() 
 
Abdul KhatriAbdul Khatri
Replace Address with Street in the SOQL
Harpreet Kaur 45Harpreet Kaur 45
ok 
Harpreet Kaur 45Harpreet Kaur 45
I got this Error

Error: Compile Error:
PostalCode FROM Lead WHERE DISTANCE(Street,:loc1, 'km') < 60 ORDER BY
^
ERROR at Row:1:Column:103
Invalid field type: ColumnType.MultiLineText. The distance() function supports only fields of type geolocation. at line 12 column 13