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
Abc234Abc234 

how to pass values to one vf to another nf page

Hi,

 

i have created one login page,So i used below code to redirect my homepage once user credentials match

 

PageReference pr= page.Homepage;
              pr.getParameters().put('id',listusers[0].id);
              pr.setRedirect(true);
              return pr;

 

But my question is,how to use the id that i pass in this page in home page

 

So in my home page i need to display like Hi rahul

 

Can anyone help me how to do this

Best Answer chosen by Admin (Salesforce Developers) 
asish1989asish1989

Hi

   After matching creadentioal .fetch id and pass it to a home page as parameter.

  In the home page get the parameter and and fatch the Firstname . Display it inthe home page In outfield

 

Here is some code you can follow...

public class Login {

 // private final Login__c log;
    public String username{get;set;}
    public String password{get;set;}
    public UserInfo__c userinfo{get;set;}
    integer m;
   
    public Login() {
  
    }
       
      public PageReference login()
      {
            if(username != '' && password != '')
            { 
              m = [select Count() from UserInfo__c where UserId__c =:username];
 
                 If (m==0)
                {
             
                   ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL, 'Login Failed.Invalid UserName .' );

                   ApexPages.addMessage(myMsg);
                   system.debug('MyMsg:'+myMsg);
                   return null;
                 }
             
               else{
          
                     userinfo = [Select id, Password__c from UserInfo__c where UserId__c =:username];
                  
                     system.debug('#########################asish########################'+userinfo.Password__c);
                
                  
                  if(userinfo.Password__c  == password )
                    { 
                      //passing the parameter....
                       PageReference nextpage = new PageReference('/apex/checkbokuses?Id='+userinfo.Id);
                       return  nextpage; 
                    }
               
                else
                 {
                 
                     ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL, 'Login Failed.Invalid Password.' );
                     ApexPages.addMessage(myMsg);
                     system.debug('MyMsg:'+myMsg);
                     return null;
                 }  
          }  
             
           
       }
    else {
        ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.Error, 'Login Failed.Enter UserName and password.' ); 
        ApexPages.addMessage(myMsg);
        system.debug('MyMsg:'+myMsg);   
        return null;
        }               
                      
    }
    
}

 Now In the checkbox page controller we have to get this.. and fetch firstname..

public UserInfo__c userinfo{get;set;}
    public Checkbokusescontroller() {
        Id id = ApexPages.currentPage().getParameters().get('Id');
      userinfo = [Select id,FirstName__c, Password__c from UserInfo__c where Id = :id];
    }

 Now In visualForce page , Display like this...

 hello :<apex:outputField value="{!userinfo.FirstName__c}"/>

 Did this post answers your questions ,if so please mark it solved so that others get benifited..

 

Thanks

asish