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
Pedro Cardoso 13Pedro Cardoso 13 

Page reference makes VF page hang on redirect to detail page.

Hi! I'm returning the following page reference in a Save method in a controller extension for a VF page:

pageReference('/lightning/r/Account/' + [Account's Id] + '/view') 

which works fine in Standard navigation mode, redirecting to the detail page, but in Console mode it just makes the VF page hang, needing to be manually closed (although the record is still saved).

Can someone please assist?

Thanks!
Best Answer chosen by Pedro Cardoso 13
Abdullah ShahidAbdullah Shahid

Hi Pedro, Apply these steps.

Here are a few suggestions for returning a page reference in a controller extension for a Visualforce page that works in both standard and console navigation modes:
Use the StandardController and redirect to the standard detail page:
ApexPages.StandardController stdController = new ApexPages.StandardController(record);
return stdController.view();
 
Use the Lightning component NavigationMixin to navigate:

NavigationMixin navigation = new NavigationMixin();
navigation.navigateToSObject(recordId);
return null;
 
Check the user's navigation mode and return different page references:

if(UserInterfaceThemeDisplay.isConsoleUser()) {
  return new PageReference('/lightning/r/Account/' + recordId + '/view'); 
} else {
  return new ApexPages.StandardController(record).view();
}
 
Use PageReference methods like setRedirect(true) to avoid hanging:

PageReference pageRef = new PageReference('/lightning/r/Account/' + recordId + '/view');
pageRef.setRedirect(true);
return pageRef;

The key is to avoid returning a Visualforce page reference directly in console mode. Hope this helps troubleshoot the issue! Let me know if any of these suggestions work or if you have any other questions.

All Answers

AshwiniAshwini (Salesforce Developers) 
Hi Pedro,
Can you please share the logic which you have used in save method?
Check for any errors in browser's developer console (F12). JavaScript errors could interfere with the proper functioning of your page.
Pedro Cardoso 13Pedro Cardoso 13
Hi Ashwini, thanks for your quick reply. I can't see any relevant errors in the console. Here's the Save method code:
   
public PageReference Save() {
        
        this.ValidationMsg1 = '';
        this.ValidationMsg2 = '';
        this.ValidationMsg3 = '';
        //this.ManualUpdMsg = '';
        
        this.ShowMsg = false;
        this.ShowMsg1 = false;
        this.ShowMsg2 = false;
        this.ShowMsg3 = false;
                
        if (this.addressChoice == 'Primary'){
         	SavePrimary();   
        }
        
        if (this.addressChoice == 'Alternative'){
         	SaveAlternative();   
        }
      
        if (this.ShowMsg) {
            String url1 = Apexpages.currentPage().getUrl();
            pageReference ref1 = new pageReference(url1);
            return ref1;
        }
        else 
        {            
            update this.acc;   
                        
            pageReference pgeRef;
            
            pgeRef = new pageReference('/lightning/r/Account/' + this.acc.Id + '/view');
            
            pgeRef.setRedirect(true);  

            return pgeRef;
        }
    }
Abdullah ShahidAbdullah Shahid

Hi Pedro, Apply these steps.

Here are a few suggestions for returning a page reference in a controller extension for a Visualforce page that works in both standard and console navigation modes:
Use the StandardController and redirect to the standard detail page:
ApexPages.StandardController stdController = new ApexPages.StandardController(record);
return stdController.view();
 
Use the Lightning component NavigationMixin to navigate:

NavigationMixin navigation = new NavigationMixin();
navigation.navigateToSObject(recordId);
return null;
 
Check the user's navigation mode and return different page references:

if(UserInterfaceThemeDisplay.isConsoleUser()) {
  return new PageReference('/lightning/r/Account/' + recordId + '/view'); 
} else {
  return new ApexPages.StandardController(record).view();
}
 
Use PageReference methods like setRedirect(true) to avoid hanging:

PageReference pageRef = new PageReference('/lightning/r/Account/' + recordId + '/view');
pageRef.setRedirect(true);
return pageRef;

The key is to avoid returning a Visualforce page reference directly in console mode. Hope this helps troubleshoot the issue! Let me know if any of these suggestions work or if you have any other questions.

This was selected as the best answer
Pedro Cardoso 13Pedro Cardoso 13
Thank you Abdullah! I've used "return new ApexPages.StandardController(this.acc).view()" and it works great.