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
R R MR R M 

Search account based on Current logged in User phone and Account Phone

Hi Friends, 

Need Visualforce page with search option account.
Should Use Current loggedin User Phone and Account phone. 
if iam trying to search with my account id = 12345.
if Account has phone number (900000001) and 
Current Loggedin User Phone number (900000001) 
Then
 User.phone==account.phone(if user phone and account phone both are same) then Account(12345) should disply on visualforce. except Account(12345) no one other account should not display. 
Please do help. this is an urgent thing need to have. 
Thanks in Advance.
YogeshMoreYogeshMore
Hi,

Following Visualforce Page and Apex Class code helps you to achieve your requirement.
1. Create new visualforce page and past following code.
<apex:page controller="SearchAccount" tabStyle="Account" sidebar="false">
  
  <apex:form id="frm">    
  <apex:slds/>
      <apex:pageBlock title="Search Account by Account Number.">
          <apex:pageBlockSection  collapsible="false">
              <apex:inputText value="{!AccountNumber}" html-placeholder="Enter Account Number.." styleClass="slds-input"/>
              <apex:commandButton value="Search" action="{!SearchAcc}" styleClass="slds-button slds-button--brand" reRender="frm"/>
          </apex:pageBlockSection>
          
          
          <apex:pageBlockSection title="Search Result" collapsible="false"/>
          <apex:pageBlockTable value="{!lstOfResult}" var="a">
              <apex:column value="{!a.Name}"/>
              <apex:column value="{!a.AccountNumber}"/>
              <apex:column value="{!a.Phone}"/>
              <apex:column value="{!a.Type}"/>
          </apex:pageBlockTable>
      </apex:pageBlock>
  </apex:form>
</apex:page>
2. Create new apex class and past following code.
public class SearchAccount{

    public String AccountNumber {get;set;}
    public List<Account> lstofResult {get;set;}
    public String userPhone {get;set;}
    
    public SearchAccount(){
        AccountNumber = '';
        lstofResult = new List<Account>();
        userPhone = [SELECT Phone FROM User WHERE Id =: UserInfo.getUserId()].Phone;     
    }
    
    public void SearchAcc(){
        lstofResult = new List<Account>();
        lstofResult = [SELECT Id, Name, AccountNumber, Phone, Type FROM Account WHERE AccountNumber =: AccountNumber AND Phone =: userPhone];
        
    }
}

3. Add phone number in current login user detail level.

4. Create sample account with same phone user phone Number.

5. Preview created visuallforce page and search account by Account Number.

Let us know if it helps you.

Your page and output look like this.


User-added image

Regards,
Yogesh More
Salesforce consultant || Salesforce Developer
more.yogesh422@gmail.com || yogeshsfdc11@gmail.com
www.yogeshmore.com || Skype:-yogesh.more44
R R MR R M
Thank you YogRaj!!!!!!!!!! 
YogeshMoreYogeshMore
Please mark above answer as SOLVED and BEST ANSWER if it helps you.
R R MR R M

YogRaj, 

Is there any possiblity to search with multple unique parameters, like , Name, phone, Email
in Above code we use only account number, in similar way want to use Name, phone, Email. 

Please do help.

 

YogeshMoreYogeshMore
Yes. It is possible, you can do this by extra filters in the query and input fields on VF page.
Check following code. I have used AND in the query where clause, you can use OR also if you want to match fields optionally.
 
<apex:page controller="SearchAccount" tabStyle="Account" sidebar="false">
  
  <apex:form id="frm">    
  <apex:slds />
      <apex:pageBlock title="Search Account by Account Number.">
          <apex:pageBlockSection collapsible="false" columns="4">
              <apex:inputText value="{!AccountName}" html-placeholder="Enter Account Name." styleClass="slds-input"/>
              <apex:inputText value="{!AccountNumber}" html-placeholder="Enter Account Number.." styleClass="slds-input"/>
              <apex:inputText value="{!AccountPhone}" html-placeholder="Enter Phone Number.." styleClass="slds-input"/>
              <apex:commandButton value="Search" action="{!SearchAcc}" styleClass="slds-button slds-button--brand" reRender="frm"/>
          </apex:pageBlockSection>
          
          
          <apex:pageBlockSection title="Search Result" collapsible="false"/>
          <apex:pageBlockTable value="{!lstOfResult}" var="a">
              <apex:column value="{!a.Name}"/>
              <apex:column value="{!a.AccountNumber}"/>
              <apex:column value="{!a.Phone}"/>
              <apex:column value="{!a.Type}"/>
          </apex:pageBlockTable>
      </apex:pageBlock>
  </apex:form>
</apex:page>
 
public class SearchAccount{
    
    public String AccountName {get;set;}
    public String AccountNumber {get;set;}
    public String AccountPhone {get;set;}
    public List<Account> lstofResult {get;set;}
    public String userPhone {get;set;}
    
    public SearchAccount(){
        AccountNumber = '';
        lstofResult = new List<Account>();
        userPhone = [SELECT Phone FROM User WHERE Id =: UserInfo.getUserId()].Phone;     
    }
    
    public void SearchAcc(){
        lstofResult = new List<Account>();
        lstofResult = [SELECT Id, Name, AccountNumber, Phone, Type FROM Account WHERE AccountNumber =: AccountNumber AND Phone =: AccountPhone AND Name =: AccountName];
        
    }
}



 
R R MR R M
Hi YogRaj, 
Not Getting Exact records please look below image. 

Please do help
User-added image