Our company still uses the custom portal with site, we have a site page as a customised portal login page collects user email and password then redirected to portal login URL like this:

    PageReference p = new PageReference(https://na3.salesforce.com/secur/login_portal.jsp?orgId=00D50035445xxx&portalId=060500000000xxx&un=xxx&pw=xxx);
    return p;

General speaking, I need to keep the default landing page/tab which is the home tab, but if an unauthorised use directly request the report tab's url, I want to redirect the user to login_portal first, then redirect to the report tab after login.

Is there a way we can set the landing URL after login in that URL?

1 Answer 1


You can try Site.Login with startUrl for navigating to specific url.

Site.login(username, password, startUrl)

We have implemented like below in Lightning. This is redirecting to given startURL after successful login.

public static String login(String username, String password, String startUrl) {
            ApexPages.PageReference lgn = Site.login(username, password, startUrl);
            return null;
        catch (Exception ex) {
            return ex.getMessage();            
  • Thanks, I'll give it a try
    – W J
    Dec 19, 2019 at 12:26

You must log in to answer this question.

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