Salesforce provides many standard components that can be used in Lightning Experience to develop an application. But sometimes, we need to create custom components to meet specific requirements.

A lookup field is a reference to another object in Salesforce. It allows you to link one object to another object.

Creating a custom lookup in an Aura component allows users to search for records of a specified object type and select a record from the results.

This can be a useful feature in many applications, as it provides a quick and efficient way for users to find and reference relevant records. By default, Salesforce provides the Lookup component, but it has some limitations, such as it only works with standard objects and only allows you to search by record name.

To overcome these limitations, we can create a custom lookup component that allows us to search and link any object in Salesforce.

In this article, we will discuss how to create a custom lookup in Aura Component. Let’s begin!

Step 1: Create the Apex Class:

The first step in creating a custom lookup is to create an Apex class that will be used to perform the search for records. In this example, we will create an Apex class called ‘customLookup’ that contains a single method called ‘searchRecords’.

This method takes two parameters: the name of the object to search for and the search string entered by the user.

The method returns a list of records that match the search criteria.

Here is an example of what the Apex Class might look like

Step 2: Create the Aura Component:

Now that we have created the Apex class, we can move on to creating the Aura component that will use it. In this example, we will create an Aura component called ‘customLookupComponent’.

The component will contain several attributes, including ‘objectName’, ‘searchString’, ‘records’, and ‘selectedRecord’. It will also include an input field for the user to enter their search criteria, a dropdown menu to select the object to search for, and a list of results returned by the Apex class.

Here is an example of what the Aura Component might look like:

Step 3: Create a JavaScript Controller:

The final step is to create a JavaScript controller to handle the user interactions and make calls to the Apex method we created in Step 1.

In this controller, we will write methods to handle the search, select, clear, and cancel actions. Here is an example of what the JavaScript controller might look like.

js-meta.xml:

Now we have set it’s path to Record Page in aura component file using “implements” attribute.

Next, we will see how to set up this aura component custom lookup in salesforce org.

Setting up the aura component custom lookup in Salesforce org.

Click on the setting icon in vs code there you find the Command Palette option click on it or Use ctrl+shift+p (keyboard shortcut).

Search open default org. It will redirect to your default org in which you have created the project.

Next, open any of the objects where you want to set this custom lookup, and then

  • Click on the setup gear icon
  • Click on the edit page and
  • Select the custom file which you have created
  • Drag and drop where you want to use in that page
  • Now save and activate it.

Now you have just created a custom lookup using Aura Component. You can see the changes in which object record page you have created.

Below is an example of what it looks like. Whatever object you will select from the Dropdown, here I have created 3 objects Account, Contact, and Opportunity, they will show you the records and you can select the record to display it on the search field and click on the cancel icon to remove that record and choose another record.

The Below Image shows how it looks when you click on any record:

Conclusion:

With the knowledge gained from this blog, you can now easily create your own custom lookup components and tailor them to your specific needs. Be sure to try out the solution and stay tuned for our upcoming blogs. Till then, happy coding!

Related Articles
Generative AI, salesforce ai, Generative AI in businesses, Generative AI Regulatory Guidelines, salesforce consulting providers, Salesforce automation, salesforce crm,

The application of Generative AI in businesses presents several benefits. However, the safe deployment of AI is still a concern. Generative AI is perhaps the most significant branch of AI that is revolutionizing business processes with its capability of generating human-like text. As the adoption of Generative AI skyrocketed, concerns about their ethical and legal […]

Read More
Salesforce CRM Platform for Q4, Salesforce CRM platform, Salesforce CRM for Q4, Salesforce data migration Services, Automate Workflows, Prepare your CRM for Q4, Q4 for marketing campaigns, Salesforce Consulting Services,

Q4, the fourth quarter of the fiscal year, is a crucial time for companies to bolster their bottom line. During this quarter, sales really pick up as businesses witness a surge in both traffic and leads because of the holiday shopping season. In B2B businesses, however, the holiday season does not add up much, but […]

Read More
Salesforce launched Sales planning, Sales planning for revenue generation, How to Increase Revenue Generation with salesforce, Sales Planning in Revenue Generation, Sales Planning Strategies, Sales Cloud implementation experts, Salesforce development services,

Sales planning plays a pivotal role in successful revenue generation strategies. Companies can achieve sustainable growth by aligning sales efforts with business objectives. Recently, global CRM leader Salesforce launched Sales planning to help companies build end-to-end plans easily using CRM data. The tool is built on Sales Cloud and provides stakeholders with a central interface […]

Read More
Sales GPT and Service GPT Boost Sales Operations

Recently, Salesforce introduced Sales GPT and Service GPT at the prestigious World Tour London event. These cutting-edge AI-powered tools harness the potential of natural language processing (NLP) and machine learning to optimize sales and service operations, drive customer satisfaction, and fuel revenue growth. Let’s explore how these AI-powered tools optimize sales and service operations. Understanding […]

Read More
Financial Services Cloud Unleashes the Power of AI, CRM, and Data to Banking Industry

Financial Services Cloud Unleashes the Power of AI, CRM, and Data to Banking Industry The Financial Service Industry is undergoing a drastic transformation driven by technology and customer expectations. Salesforce has always been the pioneer in empowering financial institutions with innovative tools and solutions. With the recent introduction of Personalized Financial Engagement along with Salesforce […]

Read More
Salesforce Launches Salesforce Starter For MSMEs At World Tour Essentials India 2023

Demonstrating its commitment to empowering businesses of all sizes, Salesforce introduced Salesforce Starter, an easy-to-use CRM for Micro, Small, and Medium Enterprise (MSME) businesses in India. At the recently concluded World Tour Essentials event held in India, Salesforce unveiled the new CRM offering for MSMEs that offers sales, service, and email outreach tools in one […]

Read More
Our Location worldwide
Indian Flag India
3rd Floor, A-10, Pegasus Tower, Sector 68, Noida, Uttar Pradesh 201301 +91-1203117884
United States of America Flag USA
333 West Brown Deer Road Unit G – 366 Milwaukee WI, USA 53217 +1(262) 310-7818
United Kingdom Flag UK
7 Bell Yard, London, WC2A 2JR +44 20 3239 9428
Canada Canada
HIC Global Solutions INC
43 Lafferty Lane, Richmond Hill, L4C 3N8, CA +1(262) 310-7818