Lightning Components - Gack error when trying to access an SObject containing an Address field via Apex Controller
Last updated 2017-05-09 ·Reference W-2380892 ·Reported By 13 users
Summary
If you create a method in your Apex controller that returns an SObject containing an Address field, it will return a gack error like this in your browser developer tools console:
An internal server error has occurred
Error ID: 1582745392-11034 (243200314)
Repro
1) Login the Org.
2) Create an Apex class containing an Address field in the SOBject (in this example "Account.BillingAddress" )
===============
public with sharing class OpportunityController {
@AuraEnabled
public static List<Opportunity> getOpportunities() {
List<Opportunity> opportunities =
[SELECT Id, Name, CloseDate, Account.BillingAddress FROM Opportunity];
return opportunities;
}
@AuraEnabled
public static Opportunity getOpportunity(Id id) {
Opportunity opportunity = [
SELECT Id, Account.Name, Name, CloseDate,
Owner.Name, Amount, Description, StageName
FROM Opportunity
WHERE Id = :id
];
// Perform isAccessible() check here
return opportunity;
}
}
=================
3) Create a Lightning Component (LoadOpp.cmp)
====================
<aura:component controller="OpportunityController">
<aura:attribute name="opportunities" type="Opportunity[]"/>
<ui:button label="Get Opportunities" press="{!c.getOpps}"/>
<aura:iteration var="opportunity" items="{!v.opportunities}">
<p>{!opportunity.Name} : {!opportunity.CloseDate}</p>
</aura:iteration>
</aura:component>
====================
4) Create a Lightning Controller for the component in step 3 (LoadOppController.js)
=====================
({
getOpps: function(cmp){
var action = cmp.get("c.getOpportunities");
action.setCallback(this, function(response){
var state = response.getState();
if (state === "SUCCESS") {
cmp.set("v.opportunities", response.getReturnValue());
}
});
$A.enqueueAction(action);
}
})
====================
5) Create a Lightning App to display your component (LoadOppApp.app)
====================
<aura:application >
<ltng:require styles="/resource/sf1bootstrap/dist/css/bootstrap.min.css" />
<div class="col-md-4" style="padding-top:10px;">
<c:LoadOpp />
</div>
</aura:application>
====================
6) In the browser, try to access your new Ligthning App like this (replace "MyDomain" with your custom domain):
https://MyDomain.lightning.force.com/c/LoadOppapp.app
7) Press the button "Get Opportunities"
Actual Result: No error is displayed in the web page and no Opportunities are retrieved.
=====================
However, if you enable the browser Developer Tools (F12) you will see a gack error like this one:
WARNING: Error in the server action response:An internal server error has occurred
Error ID: 782036608-108147 (1722168560)
CAUSE:
Apex controller returns an SObject containing an Address field (Account.BillingAddress, in this example).
If you remove "Account.BillingAddress" from the SOQL, in method "getOpportunities" the component will work.
Workaround
No workaround.
Is it Fixed?
Any unreleased services, features, statuses, or dates referenced in this or other public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make their purchase decisions based upon features that are currently available.