//Apexclass: OpportunityController.apxc
public with sharing class OpportunityController {
@AuraEnabled
public static List<Opportunity> getOpportunities() {
List<Opportunity> opportunities =
[SELECT Id, Name, CloseDate 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;
}
}
//Lightning component: Oppcomponent.cmd
<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>
//Lightning controller: OppcomponentController.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);
}
})
//Lightning Application: OppcomponentApp.App
<aura:application >
<c:OppComponent></c:OppComponent>
</aura:application>
public with sharing class OpportunityController {
@AuraEnabled
public static List<Opportunity> getOpportunities() {
List<Opportunity> opportunities =
[SELECT Id, Name, CloseDate 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;
}
}
//Lightning component: Oppcomponent.cmd
<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>
//Lightning controller: OppcomponentController.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);
}
})
//Lightning Application: OppcomponentApp.App
<aura:application >
<c:OppComponent></c:OppComponent>
</aura:application>
No comments:
Post a Comment