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
rickynrickyn 

How to get Site.Login return URL to continue on existing page

Hi, my app flow for my site requires users to login inorder to access pages after a point.  However I do not want them to return to a specific URL, I would like the user to continue to the page they attempted to go to before login was prompted.

I attempted the code below, however it does not redirect from the authentication page although authentication is successful.  It appears that using currentPage() keeps me at a stand still.  Not sure if there is another method I can use?

 

Any one have any suggestions?

 

 global PageReference login() {
        String startUrl = System.currentPageReference().getParameters().get('startURL');
        String CurrentUrl = ApexPages.currentPage().getURL();
        return Site.login(username, password, CurrentUrl);
    }

 

Best Answer chosen by Admin (Salesforce Developers) 
Navatar_DbSupNavatar_DbSup

 Hi,

 

Try the startUrl parameters in login function.

 

global PageReference login() {

 String startUrl = System.currentPageReference().getParameters().get('startURL');

 return Site.login(username, password, startUrl);

 }

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

All Answers

Navatar_DbSupNavatar_DbSup

 Hi,

 

Try the startUrl parameters in login function.

 

global PageReference login() {

 String startUrl = System.currentPageReference().getParameters().get('startURL');

 return Site.login(username, password, startUrl);

 }

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

This was selected as the best answer
CvaCva

Is the issue resolved? Please let me know.

rickynrickyn
Yes the issue was resolved using the start URL.