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
ssousanssousan 

Retrieve user information based on user input

If I have a user input his/her email in VisualForce, and after verifying the user exists, how do I use the email address to retrieve the user’s phone number or other info?

Can someone please give me an example or a URL,

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
Yoganand GadekarYoganand Gadekar

You can use following page and controller to serach user based on the email address,

You input email address and it shows you users with that email address.

 

<apex:page controller="SearchUSerByEmail">
  <apex:form > 
    <h1>Search User by email</h1>
      <apex:inputtext value="{!EnteredEmail}"/>
      <apex:commandButton value="Search" action="{!Searchuser}"/>
        <apex:pageBlock >
          <apex:Pagemessages rendered="{!ShowMessageFlag }"/>
           <apex:pageBlockTable value="{!usersList }" var="userRec" rendered="{!ShowTableFlag}">
            
             <apex:column headerValue="Email">
               <apex:outputField value="{!userRec.Email}"/>
             </apex:column>
            
             <apex:column headerValue="Name">
               <apex:outputLink value="{!userRec.id}"> {!userRec.Name}</apex:outputLink>
             </apex:column>

         </apex:pageBlockTable>
      </apex:pageBlock>
  </apex:form>
</apex:page>

 

public with sharing class SearchUSerByEmail {
public string EnteredEmail{get;set;}
public List<user> usersList{get;set;}
Public Boolean ShowMessageFlag{get;set;}
Public Boolean ShowTableFlag{get;set;}
ApexPages.Message myMsg;
    Public void Searchuser(){
    ApexPages.addMessage(new ApexPages.Message( ApexPages.Severity.info, 'There are no users with this email address'));

       ShowMessageFlag = false;
       usersList = New List<user>();
       usersList  = [select name,email from user where email=:EnteredEmail ];
       if(usersList.size()>0)
          ShowTableFlag= true;
       else
         ShowMessageFlag = True;
    }
}

 

Hit kudos and mark this as answer if this helps you, so that others can benifit from this too.

All Answers

sandeep@Salesforcesandeep@Salesforce

You should fetch user record using SOQL using "input Email"

 

as below 

 

User s = [select id from USer where email= 'a@b.com' limit 1 ];

Yoganand GadekarYoganand Gadekar

You can use following page and controller to serach user based on the email address,

You input email address and it shows you users with that email address.

 

<apex:page controller="SearchUSerByEmail">
  <apex:form > 
    <h1>Search User by email</h1>
      <apex:inputtext value="{!EnteredEmail}"/>
      <apex:commandButton value="Search" action="{!Searchuser}"/>
        <apex:pageBlock >
          <apex:Pagemessages rendered="{!ShowMessageFlag }"/>
           <apex:pageBlockTable value="{!usersList }" var="userRec" rendered="{!ShowTableFlag}">
            
             <apex:column headerValue="Email">
               <apex:outputField value="{!userRec.Email}"/>
             </apex:column>
            
             <apex:column headerValue="Name">
               <apex:outputLink value="{!userRec.id}"> {!userRec.Name}</apex:outputLink>
             </apex:column>

         </apex:pageBlockTable>
      </apex:pageBlock>
  </apex:form>
</apex:page>

 

public with sharing class SearchUSerByEmail {
public string EnteredEmail{get;set;}
public List<user> usersList{get;set;}
Public Boolean ShowMessageFlag{get;set;}
Public Boolean ShowTableFlag{get;set;}
ApexPages.Message myMsg;
    Public void Searchuser(){
    ApexPages.addMessage(new ApexPages.Message( ApexPages.Severity.info, 'There are no users with this email address'));

       ShowMessageFlag = false;
       usersList = New List<user>();
       usersList  = [select name,email from user where email=:EnteredEmail ];
       if(usersList.size()>0)
          ShowTableFlag= true;
       else
         ShowMessageFlag = True;
    }
}

 

Hit kudos and mark this as answer if this helps you, so that others can benifit from this too.

This was selected as the best answer
ssousanssousan

This works,

Thanks