I have set up basic functionality in a Lightning Component to query my sandbox for the names of all opportunities on initialization and display them in a set of cards. When I attempt to preview the app, I get an internal server error. I tried the soql in Workbench and it returned a list of results so I'm not sure what the problem is.
Here is my code:
Opportunity List View Component
<aura:component controller="OpportunityListViewController">
<aura:attribute name="opportunities" type="Opportunity" />
<aura:handler name="init" action="{!c.doInit}" value="{!this}" />
<c:cardList opportunities="{!v.opporunities}" />
</aura:component>
Opportunity List View Client Controller
({
// Load opportunities from Salesforce
doInit: function(component, event, helper) {
// Create the action
var action = component.get("c.getOpportunities");
// Add callback behavior for when response is received
action.setCallback(this, function(response) {
var state = response.getState();
if (component.isValid() && state === "SUCCESS") {
component.set("v.opportunities", response.getReturnValue());
}
else {
console.log("Failed with state: " + state);
}
});
// Send action off to be executed
$A.enqueueAction(action);
}
})
Opportunity List View Server Controller
public with sharing class OpportunityListViewController {
@AuraEnabled
public static List<Opportunity> getOpportunities() {
return [SELECT Name
FROM Opportunity];
}
}