Need one cancel button on lightning component. Case 1)- If we edit the existing record then cancel button should redirect to 'Detail Page' of record

Case 2) - If we are creating new record but want to cancel it without saving then it should redirect to listview page.

Note: We are using same component for both New Record and Edit Record.

closed as off-topic by glls, Tushar Sharma, Raul, Derek F, Pranay Jaiswal May 13 at 15:04

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on problems in code you've written must describe the specific problem and include valid code to reproduce it. For help writing short, self-contained syntactically-valid examples, see: SSCCE.org" – glls, Tushar Sharma, Raul, Derek F, Pranay Jaiswal
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    Hello, What have you tried to meet these requirements? Any place where you need help? – RedDevil May 13 at 9:51

You can do this in the JavaScript method for your cancel button (use context specific if - eg : If ID exists then it is edit, or else new). Use below event to redirect to Detail Page :

var navEvt = $A.get("e.force:navigateToSObject");
  "recordId": "Pass the Record Id of budget record Here",
  "slideDevName": "related"

Similarly below event to redirect to List View :

var navEvent = $A.get("e.force:navigateToList");
            "listViewId": listviews.Id,
            "listViewName": null,
            "scope": "Contact"
  • 1
    Worked Perfectly. Thanks Ajinkya – Pervez May 15 at 5:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.