function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
fiona gentryfiona gentry 

How To Redirect The Lightning Component To Case List View After Save

Hi Pals,

I have Salesforce lightning component which edits a Multi level picklist and then after clicking Save ,This modal is shown up again
User-added image

,Now instead of the same above modal after i click Save ,i would like to redirect to Case List View,

User-added image

I wrote the below code in JS for save Button, but still i see the same Modal screen and not the redirect
 
  onConfirm:function(component, event, helper){
        var picklist=component.find('ddLevel1');
        var picklistvalue=picklist.get('v.value');
        var picklistdep=component.find('ddLevel2');
        var picklistvaluedep2=picklistdep.get('v.value');
        var picklistoldL1=component.get('v.oldL1');
        var picklistoldL2=component.get('v.oldL2');
        var picklistoldL3=component.get('v.oldL3');
        var ertrecordGuid=component.get('v.ertGUID');
        var picklistdep3=component.find('ddLevel3');
        var picklistvaluedep3=picklistdep3.get('v.value');
        var action = component.get("c.savecasetype");
       
        action.setParams({  'level1' : picklistvalue,
                          'level2' : component.get('v.secondlevelselected'),
                          'level3' : picklistvaluedep3,
                          'oldlevel1' : picklistoldL1,
                          'oldlevel2' : picklistoldL2,
                          'oldlevel3' : picklistoldL3,
                          'guid':ertrecordGuid,
                          'id' : component.get("v.recordId")});
        
        
        var toastEvent = $A.get("e.force:showToast");
        action.setCallback(this, function(e) {
            if(e.getState()=='SUCCESS'){
                var result=e.getReturnValue();
                        
                
                if(result==='successfull'){
                    toastEvent.setParams({
                        "title": "Success!",
                        "message": "The record has been Upserted  successfully."
                         
                    });
                     var urlEvent = $A.get("e.force:navigateToURL");
    urlEvent.setParams({
      "url": "lightning/o/Case/list?filterName=Recent"
    });
    urlEvent.fire();
                    toastEvent.fire();
                   
                }else{
                   
                    toastEvent.setParams({
                        "title": "Error",
                        "message": "The record has not been Upserted  successfully."
                    });
                    toastEvent.fire();
                }
            }
          
             $A.get('e.force:refreshView').fire(); 
             
        });
        $A.enqueueAction(action);
        
          
        
    }

Any help on this is highly appreicated

Regards,
Fiona

 
Best Answer chosen by fiona gentry
SwethaSwetha (Salesforce Developers) 
HI Fiona,
I see that you are using force:navigateToURL  in your code. Instead, can you try force:navigateToList redirect to the Listview by specifying listviewId

Sample code snippet
gotoList : function (component, event, helper) {
    var action = component.get("c.getListViews");
    action.setCallback(this, function(response){
        var state = response.getState();
        if (state === "SUCCESS") {
            var listviews = response.getReturnValue();
            var navEvent = $A.get("e.force:navigateToList");
            navEvent.setParams({
                "listViewId": listviews.Id,
                "listViewName": null,
                "scope": "Case"
            });
            navEvent.fire();
        }
    });
    $A.enqueueAction(action);
}
This Apex controller returns list view named "Recently Viewed" for the Case object.
@AuraEnabled
public static List<ListView> getListViews() {
    List<ListView> listviews =
        [SELECT Id, Name FROM ListView WHERE SobjectType = 'Case' and Name='Recently Viewed Cases'];

    // Perform isAccessible() check here
    return listviews;
}
Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you