8

I have a query like below in an Apex Class in Sandbox.

query = 'SELECT Id, Name, BillingAddress, BillingLatitude, BillingLongitude  FROM   Account WHERE Name = \''+ name +'\' AND ';
query += 'DISTANCE(BillingAddress, GEOLOCATION('+lat+', '+lng+'), \'km\') < '+distance+' ORDER BY DISTANCE(BillingAddress, GEOLOCATION('+lat+', '+lng+'), \'km\') ASC';

It works perfect in sandbox. But when I try to deploy this class to live, it generate this error:

System.QueryException: No such column 'BillingAddress' on entity 'Account'. 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.

What are the possible reasons?

4
  • 1
    I presume the class is set to an API version beyond 30 in both cases?
    – Keith C
    Commented Jul 11, 2015 at 20:19
  • @KeithC Yes, you are right. API version is 34 for both
    – abdn
    Commented Jul 11, 2015 at 23:11
  • I am seeing the same error. I doubt this is some compilation error but not able to trace the root cause. Please share how you fixed it and what was the issue. Thanks in advance. Commented Apr 25, 2018 at 23:01
  • @SaumyaRanjanSatapathy check the API version of your class. BillingAddress is supported in API version 30 and beyond. In my case, the API versions were correct and still was not able to deploy code, the problem solved somewhat mysteriously. I never knew what was the problem but it just started working.
    – abdn
    Commented Apr 27, 2018 at 6:23

2 Answers 2

2

you should use the actual fields in your query... BillingCity, BillingStreet, BillingCountry... etc... same goes for mailing Address - they are special compound fields that holds few fields inside...

5
  • 1
    I can remove the BillingAddress from SELECT clause, but I really need it in the WHERE clauses. Without this I cannot find Accounts within a radius.
    – abdn
    Commented Jul 12, 2015 at 9:26
  • There is no problem with that.. you can use whatever filter you will choose - you just need to be more specific then 'Address' - you should filter by street, city, postalCode etc..
    – sfdx bomb
    Commented Jul 12, 2015 at 12:17
  • If you see I have used DISTANCE formula in the WHERE clause. It does not accept individual values.
    – abdn
    Commented Jul 12, 2015 at 18:04
  • check out this link on how to query Distance : developer.salesforce.com/forums/?id=906F0000000AdhCIAS
    – sfdx bomb
    Commented Jul 12, 2015 at 19:03
  • I am exactly doing same, except that, they are using a custom location field and I am using Standerd Compound fields as Locations. See last topic on this link
    – abdn
    Commented Jul 12, 2015 at 19:08
0

Most likely the issue is due to Field Level Security (FLS). First log in to your production environment, find the BillingAddress field and ensure that the profile you are using to deploy the class to production has at least Read access tot he BillingAddress field.

1
  • The deploying profile is Admin and has access to the field. I confirmed it. It has access to the BillingAddress individual field like BillingState etc. The BillingAddress field is also accessed from developer consoles. But simply not working in this class.
    – abdn
    Commented Jul 11, 2015 at 19:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .