5

Scenario:

After I add a geolocation custom field to my SOQL-Query, I get an Internal Server Error. When I remove it, the error disappears. I'm not using the field, it's just part of the SOQL-query. The behavior is perfectly reproducible - see the very simple source-code below.

Why I'm asking?

Important: I'm not interested at all to do something with the geolocation field, so I'm not looking for any kind of workaround. I need to clarify only the background on WHY THIS IS HAPPENING. I assume a BUG, possibly in the serialization/deserialization mechanisms behind the curtains. The reason why I get geolocation fields in my SOQL is because in my real scenario I need to use Schema methods to query ALL fields of an SObject. Then among other fields these geolocation fields (if present) are slipping in and messing up the functionality. I don't want to filter them out, because I can't see the reason why they do any harm. Lightning Components should be immune to the existence of these fields in SOQL-queries. There should be no Internal Server Error.

Prerequisite

On Account, create a custom field of type Geolocation and set it's API Name to elfMapGeolocation__c

Component:

<aura:component controller="bugLC_geolocation" implements="flexipage:availableForAllPageTypes,force:hasRecordId" access="global" >
    <aura:handler name="init" value="{!this}" action="{!c.init}" /> 
    <aura:attribute name="RecordName" type="String"  />
    TEST<br/>
    {!v.RecordName}<br/>
</aura:component>

Controller:

({
    init : function(cmp, evt, hlp) {
        console.log('init', 1 ); 
        var action = cmp.get("c.loadRecord"); 
        var accountId = '';
        action.setParams({
            recordId : cmp.get('v.recordId')
        });
        action.setCallback(this, function (res) {
            var state = res.getState();
            if(state == 'SUCCESS') {
                console.log('bugLC_geolocation.loadRecord() :: SObject=', res.getReturnValue() ); 
                cmp.set("v.RecordName", action.getReturnValue().Name );
            } else { console.log('ERROR',res.getError()); }
        });
        $A.enqueueAction(action); 
    }
})

APEX-Controller:

public class bugLC_geolocation { 
    @AuraEnabled public static Account loadRecord(Id recordId) {
        return (Account)Database.query('select Id, Name, elfMapGeolocation__c from Account where Id = :recordId')[0];
    }
}

Error in the browser console

Error: An internal server error has occurred Error ID: 453913918-140784 (-1016346842) at T.Qg (https://xe310-dev-ed.lightning.force.com/auraFW/javascript/Wm6qgqx83KGKvMBa3vagbw/aura_prod.js:513:370) at Object.onXHRReceived (https://xe310-dev-ed.lightning.force.com/components/instrumentation/beacon.js:6:206) at Object.HH.ek (https://xe310-dev-ed.lightning.force.com/auraFW/javascript/Wm6qgqx83KGKvMBa3vagbw/aura_prod.js:220:255) at pM.Do (https://xe310-dev-ed.lightning.force.com/auraFW/javascript/Wm6qgqx83KGKvMBa3vagbw/aura_prod.js:873:391) at Object.HH.ek (https://xe310-dev-ed.lightning.force.com/auraFW/javascript/Wm6qgqx83KGKvMBa3vagbw/aura_prod.js:220:255) at HH.start (https://xe310-dev-ed.lightning.force.com/auraFW/javascript/Wm6qgqx83KGKvMBa3vagbw/aura_prod.js:219:313) at XMLHttpRequest.e (https://xe310-dev-ed.lightning.force.com/auraFW/javascript/Wm6qgqx83KGKvMBa3vagbw/aura_prod.js:507:103) at XMLHttpRequest.b (https://xe310-dev-ed.lightning.force.com/auraFW/javascript/Wm6qgqx83KGKvMBa3vagbw/aura_prod.js:820:83)

Verification

If you just omit the geoloaction field from the APEX-Controller, it works flawlessly:

return (Account)Database.query('select Id, Name from Account where Id = :recordId')[0];

Appendix

Even if the documentation could be interpreted as if Compound Geolocation Fields could not be queried by APEX at all, I have experienced that it works without problems e.g. in Visualforce context or in execute anonymous context this works without error

    bugLC_geolocation.loadRecord('ANY_VALID_ID');

In contradiction to that the documentation here https://help.salesforce.com/articleView?id=custom_field_geolocate_overview.htm&type=0 says:

you can’t select the compound geolocation field in Apex. You can run SOQL queries only on a geolocation field’s components.

Not sure if here again the golden rule applies: if not explicitly documented, don't use it

  • Wonder if serializing the account, return to LC as a serialized object string and parse in the LC would cause the same issue? – Eric Aug 20 '17 at 13:40
  • @eric true, this could be investigated. But I am really curious, what is going on here behind the curtains. With Lightning I find it always very hard to follow through the jungle of things going on and the still totally insufficient error messages often don't help either (way too verbose, way too much irrelevant information). would be great if some SFDC insider could give us a hint, why this might be a feature and not a bug. – Uwe Heim Aug 20 '17 at 14:10
  • -Heim - I agree 100%. Just trying to narrow down the exact problem (although the debug should do that for someone who can read it). Lots of weird things going on that require an unfortunate amount of extra code and complexity to work around when it should just work. Like not being able to pass an Integer to the apex controller (may have been fixed) or not being able to set and send back an auraEnabled property that was null when sent to the controller. Anyway preaching to the choir I know.... – Eric Aug 20 '17 at 14:13
  • I still see this as existing problem, even after question was asked 11 months back. Any updates to anyone on this? If yes, I'll be grateful if informed here. – Sarang Jul 26 '18 at 12:51
  • 1
    @sarang because of the lag in response and the absence of a fix, I'm filtering those fields out in my SELECT * utility method. not nice but beside the small effort to implement the filter, it had no loss or any downside to do so. – Uwe Heim Jul 29 '18 at 17:28
1

Geolocation is a compound field that counts toward your org’s limits as three custom fields: one for latitude, one for longitude, and one for internal use.

you can create list views that show the field and its components, but you can’t select the compound geolocation field in Apex. You can run SOQL queries only on a geolocation field’s components.

for more better understanding of Geolocation field limitation and usage read this article: Geolocation Custom Field | Salesforce

  • 1
    How does this answer the OPs question? If it does the answer is well hidden in the education on what a geolocation field is. Can you be more specific as it relates to the question – Eric Aug 20 '17 at 5:39
  • Yes, Geolocation Field is Compound field and you can't read and set directly by appending __c to it .you have to use its component to access it . Read and set geolocation field components by appending “_latitude__s” or “_longitude_s” to the field name, instead of the usual “__c.” For example: Double theLatitude = myObject__c.aLocation__latitude__s; myObject__c.aLocation__longitude__s = theLongitude; You can’t access or set the compound value. – Siddhesh Sinkar Aug 20 '17 at 6:04
  • that's not fully true and here the documentation seems to be partially incomplete: I can query and even serialize the compound field in PURE APEX. Only when I use it in the shown context it comes to the error. – Uwe Heim Aug 20 '17 at 7:37
  • also I use my Schema-select-all-fields technique very very very often and I am sure the compound is doing NO harm if used in Visualforce context. Only here with Lightning Components this error came up. – Uwe Heim Aug 20 '17 at 7:43
  • try to execute anonymous bugLC_geolocation.loadRecord() and serialize the result to proof what I say – Uwe Heim Aug 20 '17 at 7:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.