• Rakesh Reddy1
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 0
    Replies
Hello Friends,

I have a requirement where I need to have a 'login' button on my VF page and upon click it should function like how it is going to work when we logged in as a user from a user record. In my VF Page I created a picklist field to display all the user records and a login button. 

Can you Please tell me how can I write the logic to login button.

please find the code below i have written:

VF Page:
<apex:page controller="ListOfUsers">
  <apex:form >
       <apex:pageBlock >
         <apex:pageBlockSection >
                      <apex:OutputPanel title="Select User">
                                 <apex:selectList size="1" multiselect="false"  >
                                          <apex:selectOptions value="{!ListOfUsers}" />
                                 </apex:selectList>
                        </apex:OutputPanel>
          </apex:pageBlockSection>
          <apex:commandButton value="Login"  />
      </apex:pageBlock>
</apex:form>
</apex:page>

Controller:
public class ListOfUsers {
List<SelectOption> Options = new List<SelectOption>();
      public List<SelectOption> getListOfUsers()
    {
                  
              
               for(User u : [select id ,Username,name from user]  )
               {
                          Options.add(new SelectOption(u.Id , u.Name));
               }
              return Options;
    }
}
i have a filed with picklist values 'Yes' and 'No'. I want to have a javascript button on one of the related lists, when I click on that button it should populate error if the picklist value is not 'Yes'. Can anyone please help me on this. 
Thanks