On the Contact detail page there is a Manage External User -> Login As Portal User button when the Customer Portal is enabled. Is it possible to replicate that link's functionality on a custom button on Visualforce page, while still utilising the Login-As which shows on on Audit Trail for the Salesforce User, and no Login History for the Portal User?

Log in to Portal as User


1 Answer 1


That should be possible, indeed. You can recompose the URL and forward a user to it when clicking on a custom button.

If you hover over the 'Log in to...' option and right-click, there will be an option to copy the URL or link. Copy it and paste it to a text editor. It will look similar to this:


To test if it works: if you copy-paste the bit between brackets to your browser address bar, you will get forwarded to the portal page.

Now it's a matter of finding together the bits that compose the url and creating a new url for your custom button.

In my case, it ended up somewhat like this:

PageReference loginAsUser() {
   String orgId = UserInfo.getOrganizationId();
   String contactId = theContact.Id;
   String userId = theUser.Id; // fetch this from the User table
   String portalId = '0DBD0000000ABqc'; // HARDCODED
   return new PageReference('/servlet/servlet.su?oid='+orgId+'&retURL=/'+contactId+'&sunetworkid='+portalId+'&sunetworkuserid='+userId);

  • This worked a treat, thanks, However my return URL attributes were little different as followed: return new PageReference('/servlet/servlet.su?oid='+orgId+'&retURL=/'+contactId+'&suportalid='+portalId+'&suportaluserid='+userId); Commented Mar 30, 2015 at 15:25
  • That's right. My values were from the 'Log in to Community' button. I didn't have a portal at hand :-) Commented Mar 30, 2015 at 15:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .