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 Get Case Id in Lightning such that after save action Case is shown and not related list

Dear pals,

How do i Get Case Id in Lightning such that after save Case is shown and not related list,

currently after save Most recent cases are shown ,i need to show the associated Case after save and not List view,how to achieve this

current apex class for list view is
@AuraEnabled 

public static List<ListView> getListViews() { 

    List<ListView> listviews = [SELECT Id, Name FROM ListView WHERE SobjectType = 'Case' and Name = 'Recently Viewed Cases']; 
    
    return listviews;

Lightning component cmp file is
 
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);

any help to display the Case itself after save is highly appreciated

Regards,
Fiona

 
Best Answer chosen by fiona gentry
ShivankurShivankur (Salesforce Developers) 
Hi Fiona,

Use new lightning:navigation component for that. Just add it to your component:
<lightning:navigation aura:id="navigation"/>
<aura:attribute name="recordId" type="String" />
Also ensure your component implements force:hasRecordId and in method navigate to detail page, replace the code from:
var listviews = response.getReturnValue();
            var navEvent = $A.get("e.force:navigateToList");
            navEvent.setParams({
                "listViewId": listviews.Id,
                "listViewName": null,
                "scope": "Case"
            });
            navEvent.fire();

To below format:
component.find("navigation")
    .navigate({
        "type" : "standard__recordPage",
        "attributes": {
            "recordId"      : recordId,
            "actionName"    : actionName ? actionName : "view"   //clone, edit, view
        }
    }, true);
If needed refer to example given on below link:
https://developer.salesforce.com/forums/?id=9062I000000IFsbQAG\
https://wedgecommerce.com/lightningnavigation-lightning-component/

Hope above information helps, Please mark as Best Answer so that it can help others in the future.

Thanks.