You need to sign in to do that
Don't have an account?
ShaikA
list view lightning
Hi All,
I have created component to show list view in lightning app builder but it's not showing any result.
Here is a sample code, for the List View, I've been trying to achieve for Account object.
listviewComp.cmp:
<aura:component controller="listviewController" implements="force:appHostable,flexipage:availableForAllPageTypes" access="global">
<ltng:require styles="/resource/slds0121/assets/styles/salesforce-lightning-design-system.min.css"/>
<ltng:require styles="{!$Resource.SLDS +
'/assets/styles/salesforce-lightning-design-system.css'}"/>
<aura:dependency resource="markup://force:navigateToList" type="EVENT"/>
<aura:handler name="init" value="{!this}" action="{!c.gotoList}"/>
</aura:component>
listviewCompController.js:
({
gotoList : function (component, event, helper) {
var action = component.get("c.getListViews");
action.setCallback(this, function(response){
var state = response.getState();
console.log('clicked');
if (state === "SUCCESS") {
var listviews = response.getReturnValue();
var navEvent = $A.get("e.force:navigateToList");
navEvent.setParams({
"listViewId": listviews.Id,
"listViewName": null,
"scope": "Account"
});
navEvent.fire();
}
});
$A.enqueueAction(action);
},
})
Controller:
public class listviewController {
@AuraEnabled
public static List<ListView> getListViews() {
List<ListView> listviews =
[SELECT Id, Name FROM ListView WHERE SobjectType = 'Account' limit 5];
return listviews;
}
}
even i have add component in lightning app builder, still it's not showing any result. Can anyone please explain me why it does not work and how to fix that?
Regards,
Shaik
I have created component to show list view in lightning app builder but it's not showing any result.
Here is a sample code, for the List View, I've been trying to achieve for Account object.
listviewComp.cmp:
<aura:component controller="listviewController" implements="force:appHostable,flexipage:availableForAllPageTypes" access="global">
<ltng:require styles="/resource/slds0121/assets/styles/salesforce-lightning-design-system.min.css"/>
<ltng:require styles="{!$Resource.SLDS +
'/assets/styles/salesforce-lightning-design-system.css'}"/>
<aura:dependency resource="markup://force:navigateToList" type="EVENT"/>
<aura:handler name="init" value="{!this}" action="{!c.gotoList}"/>
</aura:component>
listviewCompController.js:
({
gotoList : function (component, event, helper) {
var action = component.get("c.getListViews");
action.setCallback(this, function(response){
var state = response.getState();
console.log('clicked');
if (state === "SUCCESS") {
var listviews = response.getReturnValue();
var navEvent = $A.get("e.force:navigateToList");
navEvent.setParams({
"listViewId": listviews.Id,
"listViewName": null,
"scope": "Account"
});
navEvent.fire();
}
});
$A.enqueueAction(action);
},
})
Controller:
public class listviewController {
@AuraEnabled
public static List<ListView> getListViews() {
List<ListView> listviews =
[SELECT Id, Name FROM ListView WHERE SobjectType = 'Account' limit 5];
return listviews;
}
}
even i have add component in lightning app builder, still it's not showing any result. Can anyone please explain me why it does not work and how to fix that?
Regards,
Shaik
Your Apex controller method is returning a List<ListView>, however when you are getting the response (which is a List), you are directly trying to get the Id. You should first take the first element of the list (or the element that you need) to get its Id. Or you can modify your Apex method to return a single list? Not sure if this is the use case you are trying to implement.
I don't know if you are using Lightning Inspector in Chrome, but it is really useful as you can set breakpoints and see what your javascript is doing (eg: what is the content of your "listviews" variable)
Regards
Thanks for your replay, actually i am refrering below links to achieve this scenario.
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/ref_force_navigateToList.htm
http://salesforce.stackexchange.com/questions/108323/list-view-in-lightning
Regards,
Shaik
Sorry, I didn't know about force:navigateToList. What I have done is to copy your code into a component in my org, remove the ltng:require (because I don't have the styles loaded), create a Lightning Component tab, and it works fine.
Also I created a home page in app builder that contains this component, and it works fine too.
Do you have permissions to see the accounts? Any other information that you can give me in order I can dig more?
Regards
Sorry for late reply, it's working fine for me too.
Regards,
Shaik