You need to sign in to do that
Don't have an account?
badri nath 9
how can i load the data into lightining page?
Component:
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" controller="countRecords" >
<aura:attribute name="contactcount" type="integer" />
<aura:attribute name="Accountcount" type="integer" />
<aura:attribute name="oppcount" type="integer" />
<div style = "slds">
<lightning:button onclick="{!c.count}" title="to get the total numbe of records" class="slds-button-sucess" label="count" variant="brand" iconName="utility:people" iconPosition="left" /><br/>
Totalnumber of accounts:<ui:outputText value="{!v.contactcount}" title="Totalnumber of accounts" class="slds-output"/><br/>
Totalnumber of contacts:<ui:outputText value="{!v.Accountcount}" title="Totalnumber of contacts" class="slds-output"/><br/>
Totalnumber of opprts:<ui:outputText value="{!v.oppcount}" title="Totalnumber of opprts" class="slds-output"/><br/>
</div>
</aura:component>
Controller:
({
count : function(cpnt, event, helper) {
var action = cpnt.get("c.getrecords");
var accounts = cpnt.get("v.contactcount");
var contacts = cpnt.get("v.Accountcount");
var opprts = cpnt.get("v.oppcount");
action.setParams({
"accounts": accounts,
"contacts": contacts ,
"opprts": opprts ,
});
action.setCallback(this, function(a) {
var state = a.getState();
if (state === "SUCCESS") {
alert("Records are counted sucessfully");
}
});
$A.enqueueAction(action);
}
})
Apex controller:
public class countRecords {
/* @AuraEnabled public integer accounts {get;set;}
@AuraEnabled public integer contacts {get;set;}
@AuraEnabled public integer opprts {get;set;}*/
@AuraEnabled
Public static void getrecords(integer accounts,integer contacts, integer opprts){
accounts = [select count() from Account];
contacts = [select count() from contact];
opprts = [select count() from Opportunitie__c];
system.debug('>>>>>>>>>>>'+accounts);
}
}
Thanks in advance
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" controller="countRecords" >
<aura:attribute name="contactcount" type="integer" />
<aura:attribute name="Accountcount" type="integer" />
<aura:attribute name="oppcount" type="integer" />
<div style = "slds">
<lightning:button onclick="{!c.count}" title="to get the total numbe of records" class="slds-button-sucess" label="count" variant="brand" iconName="utility:people" iconPosition="left" /><br/>
Totalnumber of accounts:<ui:outputText value="{!v.contactcount}" title="Totalnumber of accounts" class="slds-output"/><br/>
Totalnumber of contacts:<ui:outputText value="{!v.Accountcount}" title="Totalnumber of contacts" class="slds-output"/><br/>
Totalnumber of opprts:<ui:outputText value="{!v.oppcount}" title="Totalnumber of opprts" class="slds-output"/><br/>
</div>
</aura:component>
Controller:
({
count : function(cpnt, event, helper) {
var action = cpnt.get("c.getrecords");
var accounts = cpnt.get("v.contactcount");
var contacts = cpnt.get("v.Accountcount");
var opprts = cpnt.get("v.oppcount");
action.setParams({
"accounts": accounts,
"contacts": contacts ,
"opprts": opprts ,
});
action.setCallback(this, function(a) {
var state = a.getState();
if (state === "SUCCESS") {
alert("Records are counted sucessfully");
}
});
$A.enqueueAction(action);
}
})
Apex controller:
public class countRecords {
/* @AuraEnabled public integer accounts {get;set;}
@AuraEnabled public integer contacts {get;set;}
@AuraEnabled public integer opprts {get;set;}*/
@AuraEnabled
Public static void getrecords(integer accounts,integer contacts, integer opprts){
accounts = [select count() from Account];
contacts = [select count() from contact];
opprts = [select count() from Opportunitie__c];
system.debug('>>>>>>>>>>>'+accounts);
}
}
Thanks in advance
Here is the updated code:
And here is the output after click of the count button:
I advise you to use wrapper instead of a list for more complex return values.
Hope this would have helped you,
Sandeep
All Answers
Below code will work for your case:
I also suggest you to refer this link for lightning development in future:
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/intro_framework.htm (Online)
https://resources.docs.salesforce.com/sfdc/pdf/lightning.pdf (Offline)
Hope this helps,
Sandeep
code you written above is not working fine , and you didn't call server side method(getrecords),the error shows below ,
c:cmpntcount$controller$count [action is not defined] Failing descriptor: {c:cmpntcount$controller$count}
hope you will get back with solution ,
Thanks
Here is the updated code:
And here is the output after click of the count button:
I advise you to use wrapper instead of a list for more complex return values.
Hope this would have helped you,
Sandeep
above code working fine you forget to define variable for action(Line 19),
Thank you for your wonderfull Response,