I'm attempting to build a google map page that displays all sites within 5km of a certain point. I've added a Geolocation field called Location__c, and attempting to build a list of the sites in the controller using the following:

List<Site__c> sitesIn5Km = [select Location__Latitude__s, Location__Longitude__s, Id,Name from Site__c where Distance(Location__c,GEOLOCATION(-0.15971300,51.46643590),'km')<=5];

however eclipse is giving me the error No such column Location__c on entity Site__c

looking in the schema both Location__Latitude__s and Location__Longitude__s but not Location__c.

Any ideas?

  • Does your query work if you open the developer console and run the query anonymously? I've experienced weird issues with eclipse when using pre-view features. Oct 2, 2012 at 15:36

4 Answers 4


The issue has made it onto the Salesforce Known Issues list. here is the link

It seems that if you are able to bump the version on all your classes up to 26 that might solve the problem. However If you have a lot of classes be very careful before doing this. Changing the version of your classes can have unintended consequences and break existing functionality


Paul, any chance that you are working in an org with a Namespace (e.g. a Managed Package development org)? I created an identically-named geolocation field (Location__c) on the Account object in my org, and ran the following query, but it only worked when I prepended the namespace prefix (e.g. SFDC auto-namespace-prepending logic is not working, I guess):

List<Account> accs = [select Location__Latitude__s, Location__Longitude__s, Name
     from Account 
     where DISTANCE(namespace__Location__c,GEOLOCATION(-0.15971300,51.46643590),'km')<=5];

Again, this only worked when I used namespace__Location__c, NOT Location__c.

As far as your syntax and use of the field, I believe that you are using it correctly. Here is some information from jcai posted on the engineering blog after the feature came out in Pilot in Summer 12:

Unfortunately, no official doc is available for pilot. Usage is actually quite simple.

You add location field just like any other custom field.

two functions are provided:

LOCATION(lat, lng), and DISTANCE(loc1, loc2, “km”/”mi”)

component reference suffix is __s, for example, if you have a loc field,

you can use loc__Latitude__s, and loc__Longitude__s to get the latitude and longitude of the loc field in formula and in SOQL/Apex

Some caveats for pilot release

  1. ORDER BY is not supported

  2. SELECT works on component levels only, i.e., SELECT loc__Latitude__s FROM object works, but SELECT loc__c FROM object does not

  3. DISTANCE function in WHERE clause needs to be strictly in the format of

DISTANCE(loc__c, GEOLOCATION(<lat>, <lng>), "mi"/"km") in which loc__c is the field of the object, and GEOLOCATION(<lat>, <lng>) is the literal form of a geo location point

  • i do have a managed package installed but im not referring to an object in that managed package so shouldn't be necessary?? or should it...
    – paul
    Sep 26, 2012 at 15:48
  • It shouldn't be necessary, but this is probably due to a bug. As for referring to non-packaged objects by an org's namespace, this is the documented behavior. As soon as you have a namespace in your org, you can then refer to ANY object in that org (not just objects that you've included in that org's managed package) by the namespace prefix, e.g. if you have ObjectInPackage__c and ObjectNOTInPackage__c, you can always, from within that org, refer to these objects by ns__ObjectInPackage__c and ns__ObjectNOTInPackage__c, respectively.
    – zachelrath
    Sep 26, 2012 at 20:02
  • no joy unfortunately, thanks for the suggestion though. will try getting it set up in a clean developer account.
    – paul
    Sep 27, 2012 at 9:31
  • In case anyone else comes up against this... it's sort of resolved now that its been officially released in beta. When working through the UI i still get error when i save the VF page, however if i save the controller last it all works fine. and it works fine when saving through eclipse. Im guessing this'll be ironed out in time for full release.
    – paul
    Oct 26, 2012 at 7:58

Silly detail.. But are you using the latest version of eclipse? if you haven't upgraded both eclipse tool and the class version number to 26 you will get this error..

  • This would be my guess as well. The way your question is worded (Error is coming from Eclipse) sounds like an error when you're trying to save the class and that it's related to the api version of the controller apex class. Jan 8, 2013 at 22:03

I encountered this in our production org and investigated further. I thought I'd give back to the community by posting what I discovered.

I have a function called getAllFieldsSQL that gets all fields on an object via field describe info in order to do a SELECT * "of sorts" in apex soql. This function is in a class at API version 26.

Two geo location fields were recently added via the salesforce website ui
Location_Longitude__c type - geolocation, decimal, 7 places
Location_Latitude__c type - geolocation, decimal, 7 places

Upon doing so, code that queries the object fields returned by my getAllFieldsSQL encounters an exception: No such column Location_Longitude__c (or Location_Latitude__c)

I system.debug'd the name and type info on each field and discovered that though we added only the two fields with the above names, schemaMap.get(ObjName).getDescribe().fields.getMap() is returning two sets of fields in the map.

Location_Longitude__c type - LOCATION
Location_Latitude__c type - LOCATION


Location_Longitude__Latitude__s DOUBLE
Location_Latitude__Longitude__s DOUBLE

Querying for the Location_Longitude__c fails with that error, but querying the other value Location_Longitude_Latitude_s works fine

I dont really need the lat/long fields in my query so I worked around my error by ignoreing fields of type 'LOCATION'

My loop for the field info now looks like so:

Map<String, Schema.SObjectField> fldObjMap = 
List<Schema.SObjectField> fldObjMapValues = fldObjMap.values();

string theFields = '';
for(Schema.SObjectField s : fldObjMapValues){
    DescribeFieldResult sfdesc = s.getDescribe();
    string sName = sfdesc.getName();
    string sType = sfdesc.getType().name();
    //system.debug(sName + ' ' + sType );
    /*salesforce bug
     Two fields are found, for geolocation fields - Location_Longitude__c LOCATION 
     AND Location_Longitude__Latitude__s DOUBLE
     Trying to query for the first (Location_Longitude__c LOCATION) yields No such 
     column 'Location_Longitude__c' 
     but Location_Longitude__Latitude__s works. 

    if(sType == 'LOCATION') continue; //ignore geo location fields

    //Or just ignore the fields explicitly, by name
    //if(sName.equalsIgnoreCase('Location_Longitude__c')) continue;
    //if(sName.equalsIgnoreCase('Location_Latitude__c')) continue;

   theFields += sName + ',';
theFields = theFields.subString(0, theFields.length() - 1);
  • Welcome to the SFSE. I edited your post to use code formatting where it had used blockquote. There's more information in the markdown editing help and you can also use the controls on the toolbar above the textarea of your post. Jul 13, 2013 at 12:48
  • If you'd like to take this approach for a SELECT * method and don't want to burn your 100 field describes limit per transaction: try something like if(s.replace('__c', '__latitude__s') != s && objectFields.get(s.replace('__c', '__latitude__s')) != null){ continue; } Jan 5, 2014 at 20:46

You must log in to answer this question.

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