How to Redirect Users Back to Original ListView After Canceling

How to Redirect Users Back to Original ListView After Canceling

On December 24, 2025, Posted by , In Salesforce Technical Questions, With Comments Off on How to Redirect Users Back to Original ListView After Canceling
Salesforce Technical Questions with Answers Apex, LWC, Marketing Cloud

Question:

How Can I Redirect Back to the Original List View on Canceling Record Creation?

I have a custom button on Opportunity that opens the new record creation page with a predefined stage using this URL:

/lightning/o/Opportunity/new?defaultFieldValues=StageName=Prospect

This button is launched from a list view. When a user cancels the record creation, I want to return them to the original list view from which they started. Currently, I can redirect to a specific list view by adding parameters like:

&count=1&nooverride=1
&navigationLocation=LIST_VIEW
&backgroundContext=%2Flightning%2Fo%2FOpportunity%2Flist%3FfilterName%3D__Recent
&useRecordTypeCheck=1
&recordTypeId={!Opportunity.RecordTypeId}

Replacing __Recent with any list view API name works, but how can I dynamically redirect to the list view I started with without hardcoding its API name? I tried using currentPageUrl but it redirected me to a non-existent list view. Is there another parameter or approach that I should use for this redirection?

Answer:

When creating a custom button in Salesforce on the Opportunity object that predefines a record’s stage, it’s common to want the user to return to the list view they started from, especially if the operation is canceled. Unfortunately, Salesforce doesn’t provide a direct parameter to capture and return to the current list view. However, you can achieve this functionality by leveraging URL parameters and Salesforce merge fields. This method will show how to redirect users back to the original ListView after canceling an action.

Enroll in our Salesforce course online to gain practical experience through real-world projects. Register for a free demo today and take the first step towards advancing your career..!

By utilizing the backgroundContext parameter with the $Site.CurrentSiteUrl merge field, you can ensure that users are redirected back to the list view from which they initiated the record creation after they click ‘Cancel’.

Here’s how you can configure the custom button URL:

/lightning/o/Opportunity/new?defaultFieldValues=StageName=Prospect
&count=1&nooverride=1
&navigationLocation=LIST_VIEW
&backgroundContext={!$Site.CurrentSiteUrl}
&useRecordTypeCheck=1

Explanation of Key Parameters:

  • defaultFieldValues=StageName=Prospect: Pre-fills the StageName field with the value “Prospect” during the record creation process.
  • count=1&nooverride=1: Ensures the page doesn’t override the number of records being displayed.
  • navigationLocation=LIST_VIEW: Indicates that the navigation should go back to the list view.
  • backgroundContext={!$Site.CurrentSiteUrl}: This merge field captures the current URL (including the list view) and ensures that users are returned to the same list view after canceling.
  • useRecordTypeCheck=1: Ensures that if Record Types are enabled, the appropriate one is used.

Why This Works:

Using the $Site.CurrentSiteUrl ensures that the URL dynamically adjusts based on the list view or page the user is on when they click the button. This allows seamless redirection after the user cancels the operation, improving the user experience by returning them to their original context. This method clearly demonstrates how to redirect users back to the original ListView after they cancel an operation.

Launch Your Salesforce Learning Journey Today!

Our comprehensive Salesforce training in India provides an immersive experience, equipping you with the skills needed to thrive in the CRM industry. The program covers essential areas like Salesforce Admin, Developer, and AI, blending solid theoretical knowledge with practical hands-on experience. Through live projects and assignments, you’ll develop the expertise to tackle complex business problems using Salesforce solutions. Our expert instructors are dedicated to helping you enhance both your technical skills and industry insights.

Beyond technical training, our Salesforce course online offers personalized mentorship, exam preparation support, and interview coaching to help you stand out in a competitive job market. You’ll gain access to in-depth study materials, real-world projects, and continuous support throughout your learning journey. By the end of the course, you’ll be fully prepared for certification exams and equipped with the practical skills that employers seek.

Start your Salesforce career with us and unlock exciting opportunities. Enroll now for a FREE Demo..!

Comments are closed.