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
Dominic SebastianDominic Sebastian 

Fetching the User ID at Sites while redirecting a page.

While executing the login for a portal at Site.com. The login portal will reditrct to another page. The problem that I am dealing with is that, the page to which it's redirected needs the User. Id in order for it to process.  I have used the "ApexPages.currentPage().getParameters().get('Id')". In order to fetch it. But somehow, it'snot working.

global class SiteMiniMouseController{
    global String username {get; set;}
    global String password {get; set;}

    global PageReference login() {       
        String startUrl = System.currentPageReference().getParameters().get('start');
       String PageId= UserInfo.getUserId() ;
  
        String pageUrl = '/apex/MickeyMouse?id=PageId';
               
        if (startURL != '' && startUrl != NULL && startUrl != 'null') {
             pageUrl = startUrl;
            // pageUrL = PageId;
        }
       
        System.debug('pageURL: ' + pageURL);
       
        PageReference page =  Site.login(username, password, pageUrl);
        if (page == null ) {
            System.debug('Invalid username or password!');
        }
        return page;
    }
    global SiteMiniMouseController(){}
}
Best Answer chosen by Dominic Sebastian
logontokartiklogontokartik
Your pageURL construct is wrong

Try this instead. Thank you

String pageUrl = '/apex/MickeyMouse?id='+PageId;


All Answers

logontokartiklogontokartik
Your pageURL construct is wrong

Try this instead. Thank you

String pageUrl = '/apex/MickeyMouse?id='+PageId;


This was selected as the best answer
Ramu_SFDCRamu_SFDC
UserInfo.getUserId() should get the user id of the logged in user. I noticed that you are assigning this code('UserInfo.getUserId()') to the pageid string variable. Please verify.


Dominic SebastianDominic Sebastian
Yes, I am Ramu_SFDC. I am trying to get the User Id of the logged in user.
Dominic SebastianDominic Sebastian
I am still not able to execute the "String pageUrl = '/apex/MickeyMouse?id='+PageId;"   page. I am getting an error stating "Error: Error occurred while loading a Visualforce page."
logontokartiklogontokartik
have your tried looking at the debug logs to see what error it is? 
Dominic SebastianDominic Sebastian
I got a way to solve the error. I had to enable the VisualForce pages at the Sites.