Searching Account Name Via Search Key Through Salesforce Visualforce Page

Introduction

Visualforce is a web development framework that enables developers to build sophisticated, custom user interfaces for mobile and desktop apps that can be hosted on the Lightning Platform. You can use Visualforce to build apps that align with the styling of Lightning Experience, as well as your own completely custom interface. Visualforce enables developers to extend Salesforce’s built-in features, replace them with new functionality, and build completely new apps. Use powerful built-in standard controller features, or write your own custom business logic in Apex. You can build functionality for your own organization, or create apps for sale in the AppExchange.

Salesforce provides a range of ways that you can use Visualforce within your organization. You can extend Salesforce’s built-in features, replace them with new functionality, and build completely new apps.

See the steps below to search Account Name via Search Key through Salesforce Visualforce Page:

Step 1: Create a Visualforce page

Firstly we have to create a Visualforce Page and for that go to setup->Developer console. At Developer, console Click on New to create a Visualforce page and use the code mentioned below:

<apex:page Controller="searchBox">
    <apex:form >
        <apex:inputText value="{!searchKey}" label="Input"/><br/>
        <apex:commandButton value="Enter" action="{!search}"/>
        <apex:pageBlock title="Searched Accounts are:-">
            <apex:pageBlockTable value="{!acc}" var="a">
                <apex:column value="{!a.name}"/>
                <apex:column value="{!a.id}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Step 2: Create an Apex class that fetches the record from the Visualforce Page

Apex is a strongly typed, object-oriented programming language that you use to execute code in your Salesforce instance. The Apex syntax is similar to Java and also includes built-in support for database operations. In this module, you create an EmailManager class that encapsulates the logic to send confirmation emails to the conference speakers.

Now the page which we have created will call from the apex class and use the code mentioned below:-

public class searchBox {
    public list <Account> acc {get;set;}
    public String searchKey {get;set;}
    public searchBox( ) {} 
    public void search(){
        string searchquery='select Name,id from account where name like \ +searchKey+'%\'';
        acc= Database.query(searchquery);
    }
}

Step 3: Test the Application

Popular Salesforce Blogs