You need to sign in to do that
Don't have an account?
Create a Lightning Component to display Case information
<aura:component controller="DisplayCaseController" implements="force:appHostable">
<aura:attribute name="record" type="Case[]"/>
<ui:inputNumber label="Case ID" aura:id="CaseID"/><br/><br/>
<ui:button label="Get Case" press="{ !c.getCaseFromId }"/><br/><br/>
<aura:iteration var="c" items="{!v.record}">
<p>{!c.Subject} : {!c.Description} : {!c.Status}</p>
</aura:iteration>
</aura:component>
client-side controller:-
({
getCaseFromId : function(component) {
var caseID = component.find("CaseID").get("v.value");
var action = component.get("c.getCaseFromId");
action.setCallback(this, function(response){
var state = response.getState();
if (state === "SUCCESS") {
component.set("v.record", response.getReturnValue());
}
});
$A.enqueueAction(action);
}
})
public class DisplayCaseController {
@AuraEnabled
public static Case getCaseFromId(Id caseID) {
if(caseID == null) {
return [SELECT ID, Subject, Description, STATUS from Case LIMIT 1];
}
List<Case> cases = [ SELECT Id, Subject, Description, Status from CASE where ID = :caseID ];
if(cases.size() == 0) {
return [SELECT ID, Subject, Description, STATUS from Case LIMIT 1];
} else {
return cases[0];
}
}
}
Challenge not yet complete... here's what's wrong:
The client side controller does not refer to the 'getCaseFromId' method of the Apex controller class
Thnaks In Advance
Prashant
Component: Controller:
Apex:
Component:
JS Controller:
Apex:
Component: (DisplayCase)
<aura:component controller="DisplayCaseController">
<aura:attribute name="record" type="case[]"/>
<ui:button label="display case" press="{!c.getCaseFromId}"/>
<aura:iteration items="{!v.record}" var="record">
{!v.record.Subject},{!v.record.Description},{!v.record.status}
</aura:iteration>
</aura:component>
*************************************************************************************************
Apex Controller: (DisplayCaseController)
public class DisplayCaseController {
@AuraEnabled
public static Case getCaseFromId(Id caseID) {
if(caseID == null) {
return [SELECT ID, Subject, Description, STATUS from Case LIMIT 1];
}
List<Case> cases = [ SELECT Id, Subject, Description, Status from CASE where ID = :caseID ];
if(cases.size() == 0) {
return [SELECT ID, Subject, Description, STATUS from Case LIMIT 1];
} else {
return cases[0];
}
}
}
*************************************************************************************************
JsController: (DisplayCaseController.js)
({
getCaseFromId: function(component,record,callback) {
var action = component.get("c.getCaseFromId");
action.setcallback(this,function(response){
var state = response.getState();
if(state === "SUCCESS"){
component.set("v.record",response.getReturnValue());
}
});
$A.enqueueAction(action);
}
})
Thanks!
1. we can get the values by calling Iteration Variable as
<aura:iteration var="cse" items="{!v.record}">
{!cse.CaseNumber} : {!cse.Subject} : {!cse.Description} : {!cse.Status}
2. And If Are Use unique names for client-side and server-side actions in a component. then it will run recursively