Tuesday 7 August 2018

How To Redirect On List View In Lightning

Arpit Sharma

In this tutorial we will see how we can navigate to list view in lightning,

Salesforce recommended us to stop using anchor tag for redirection because of security concerns.

That's why for redirection I used events trigger and but you need to take care because it will not work if we will use it without tabs, home page etc.

So for make it work I have created one component Named NavigateEventComponentExample and used that component on tab. below is code snippet for component.

<aura:component implements="force:appHostable" controller="NavigateEventController">
    <h1 class="slds-m-around_small">Redirect to List View</h1>
    <lightning:button class="slds-m-around_small" label="Go" onclick="{!c.goToListView}"> 

Let’s understand above component 

1. I used implements="force:appHostable" to make it available for tabs.
2. Go Button that will help us to trigger event firing.

When we will click on above button then goToListView function in controller of NavigateEventComponentExample will call.
Below is code snippet for controller

    goToListView : function(component, event, helper){
        var listViewRedirectEvent = $A.get('e.force:navigateToList');
         "listViewId": '00B6A000007jQu0UAE',
            "listViewName": 'All_Leads',
            "scope": "Lead"     
In above component
1. We have created object for event and by use of e.force:navigateToList we tell event to redirect us to list view when fire.
2. Set event parameters i.e. List view Id, Name and scope(In our case scope is Lead).
3. Fire the event.
Once event get fire then user will redirect to list view of given Id and object.

Let me know if you found any issue in above code snippet and understanding.

About the Author

Arpit Sharma / Author & Editor

Certified Salesforce Developer | Salesforce Developer at Cognizant | Blogger


Post a Comment