Find your content:

Search form

You are here

No such column Location__c using Geolocation field beta

 
Share

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?


Attribution to: paul

Possible Suggestion/Solution #1

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


Attribution to: zachelrath

Possible Suggestion/Solution #2

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

AND

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 = 
    schemaMap.get(ObjName).getDescribe().fields.getMap();
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
     https://success.salesforce.com/issues_view?id=a1p30000000SpfnAAC
     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);

Attribution to: Mikey-CP

Possible Suggestion/Solution #3

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..


Attribution to: Benjamin Pirih

Possible Suggestion/Solution #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


Attribution to: Daniel Blackhall
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/1682

My Block Status

My Block Content