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
Akshay PaiAkshay Pai 

URL.getSalesforceBaseUrl() function is not working as expected in Lightening experience

Hi All,

I have a Custom button which uses Visualforce page with custom controller. Custom controller's save function does some calculations and redirects to Origin record page where my custon button is placed.
VF PAGE:

<apex:page standardController="ABC__c"  extensions="CustomController" action="{!save}">

</apex:page>
 
Custom controller:

public class CustomController {
    
// Constructor and other intializations

    public PageReference save()
    {
        try{
        
           // performing some calculations
            
            //return reference. 
            String returnUrl = URL.getSalesforceBaseUrl().toExternalForm() +'/' + EncodingUtil.URLENCODE(ApexPages.currentPage().getParameters().get(retURL),'UTF-8');        
            return new Pagereference(returnUrl);
			
        }catch(System.DMLException e){
             ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,e.getDmlMessage(0))); 
            return null;
        }
            
    } 
}




This is working as expected in Salesforce classic. But in Lightening experience the return page is opening in new tab and showing origin page in classic version.  I want to redirect the page to my Origin record page where my custon button is placed in Lightening experience and in the same tab.
Can anyone please help me to achieve this? Thanks in advace.
Ramakrishna Reddy GouniRamakrishna Reddy Gouni
Classic and Lightning both are different, classic for every navigation page should be refreshed whereas lightning not like that. 

So try to use navigate to URL event, it works for you. I hope your project running in Lightning Environment.