I am able to display current logged in user accounts using Lightning components. But it is displaying empty list, when adding lightning component in a VF page(AccPage) and trying to access that page from another page(displayPage).
I think I need to pass parameter but i have no idea how to do that can anyone help me with this.
Here is my code
DISPLAY PAGE :
<apex:page>
<table align="top" float="right">
<tr>
<td Style="padding-right: 60px;"> <table>
<tr>
<td>
<div class="img">
**<!-- Here I am giving Link for AccPage-->**
<a
href="https://mylightpackage-dev-ed--mylightpackage5.na16.visual.force.com/apex/AccPage">
<img src="{!$Resource.Img1}" alt="Accounts"
class="imagestyleHomePage" />
</a>
<div class="desc">Accounts</div>
</div>
</td>
<td>
<div class="img">
<a
href="https://mylightpackage-dev-ed--mylightpackage5.na16.visual.force.com/apex/PageToShowCases">
<img src="{!$Resource.Img2}" alt="Cases"
class="imagestyleHomePage" />
</a>
<div class="desc">Cases</div>
</div>
</td></tr>
<tr>
</table>
</apex:page>
AccPage :
<apex:page standardStylesheets="false" sidebar="false" >
<apex:includeScript value="/lightning/lightning.out.js" />
<div id="lightning" />
<script>
$Lightning.use("c:AccInfoApp", function() {
$Lightning.createComponent("c:AccInfoComponent",
{ label : "" },
"lightning",
function(cmp) {
// do some stuff
});
});
</script>
</apex:page>
Apex Controller(AccountInfo) :
public class AccountInfo {
@AuraEnabled
public static List<Account> getAccounts() {
ID contactId = [Select contactid from User where id =: Userinfo.getUserid()].contactId;
ID AccID = [Select AccountID from Contact where id =: contactid ].AccountId;
List<Account> acc =[SELECT Id, name,AccountNumber,AnnualRevenue
FROM Account where Id =: AccID];
return acc;
}
}
AccInfoComponent:
<aura:component controller="AccountInfo">
<aura:attribute name="accountRows" type="Object[]"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<table align="left">
<aura:iteration var="acc" items="{!v.accountRows}">
<tr class="border_bottom">
<td style="padding-right: 200px;">Account Name</td>
<td style="padding-right: 200px;"> {!acc.Name} </td>
</tr><hr class="hrcls"/>
<tr>
<td>Account Number</td>
<td> {!acc.AccountNumber} </td>
</tr><hr class="hrcls"/>
</aura:iteration>
</table>
</aura:component>
AccInfoComponentHelper:
({
getAllaccounts : function(component, event, helper) {
var action = component.get("c.getAccounts");
action.setCallback(this, function(a){
component.set("v.accountRows", a.getReturnValue());
});
$A.enqueueAction(action);
}
})