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
Captain62Captain62 

How to get the originally requested URL in a Community login page when using /networks/session/create?

We have an OAuth enabled website that is hooked into a Salesforce Community for our customers and partners, that lets them login using their Community username/password (or if they are already logged into the Community it lets them right in). This works correctly.

Internal users, however, cannot login directly to a Community using their Salesforce username/password, and instead have to use a special link built into the Community login page: https://<org>.my.salesforce.com/servlet/networks/session/create?site=XXXXXXX. However, that link ALWAYS takes them to the Community homepage, and not the original URL they typed into the browser. I have read that there is an additional parameter you can add to /networks/session/create called "&url=<url>" to send them to a specific URL, but I do not know how to lookup the original URL since it is wrapped up in the OAuth request, and not present in the Page's URL

For reference the URL shown in the browser is
https://<my community.com>/setup/secur/RemoteAccessAuthorizationPage.apexp?source=YYYYYYY

How do I access the original requested URL so I can append it to /networks/session/create so Internal Users are send to the correct destination URL after logging in?
Best Answer chosen by Captain62
Captain62Captain62
I found my own answer through trial and error. You can use the $CurrentPage.parameters.startURL parameter to get the original destination URL.

For example:
/servlet/networks/session/create?site={!$Site.SiteId}&url={!$CurrentPage.parameters.startURL}

All Answers

Captain62Captain62
I found my own answer through trial and error. You can use the $CurrentPage.parameters.startURL parameter to get the original destination URL.

For example:
/servlet/networks/session/create?site={!$Site.SiteId}&url={!$CurrentPage.parameters.startURL}
This was selected as the best answer
NZArchitectNZArchitect

I liked your answer (Up Vote):

But I had 2 issues not with yours but more the other info I found, mainly only because the documentation is limited and these scenario pop up in other blogs but with no real rule of thumb.

1. most URLs consist of a double back slash //
Which personally I thought was strange:
e.g.
https://<org>.my.salesforce.com//servlet/networks/session/create
WE used the double backslsh and it worked for us. Yet to test a single.

2. they also included further parameters:
e.g.
inst=0, or inst=D, or etc... etc...
Not sure what this does.
WE used inst=0 and it worked for us, yet to test other options here

Anyway I hope someone can expand on this so it is helpful to other people in the future.

NZArchitectNZArchitect

We ended up using exactly the same syntax as Captain62:

 

window.open("https://customdomain.my.salesforce.com/servlet/networks/session/create? site={!ourSiteId}& url=https://customsite.force.com/portal?accountid={!Account.Id}","_blank");

NZArchitectNZArchitect
http://salesforce.stackexchange.com/questions/157481/what-is-the-inst-parameter-for-in-our-case-inst-0