How to Customize Fields in Add Products Button?

How to Customize Fields in Add Products Button?

On March 23, 2025, Posted by , In Apex, With Comments Off on How to Customize Fields in Add Products Button?
How to Customize Fields in Add Products Button

Question:

When I click the standard Add Products button in Salesforce (e.g., on an Opportunity), the resulting screen displays certain fields as columns, which seem to come from the Product search layout. However, after selecting products, I am taken to another screen where I want to display additional custom fields that I created on the PricebookEntry object. I cannot figure out where to configure these fields so that they appear. How can I achieve this?

CRS Info Solutions offers top-notch Salesforce training in India, combining Admin, Developer, and AI expertise with real-world projects. Gain hands-on experience, personalized guidance, and job-ready skills—kickstart your career with a free demo session today!

Answer:

The fields shown when using the Add Products button are controlled by different configurations depending on the step in the process:

1. First Screen (Product Selection Columns):

The columns displayed here are configured in the Search Layouts for the Product object.
To modify them:

  • Navigate to Object Manager → Product → Search Layouts.
  • Edit the relevant layout (e.g., Lookup Dialogs or List View).
  • Add or remove fields as desired.

2. Second Screen (After Selecting Products):

The fields shown on this screen are controlled by the Field Set on the PricebookEntry object. Salesforce uses field sets to dynamically control what appears in certain standard screens.
To customize the fields:

If a relevant field set does not exist or is not editable, the functionality may be part of a managed package or hardcoded in Salesforce, in which case customization would not be possible without additional customization.

3. Alternative Solution Using Custom Lightning Component or Flow:

If the standard Salesforce behavior does not allow the flexibility you need, you can override the Add Products button with a custom solution.
Create a custom Lightning Component, Visualforce page, or Flow that mimics the product selection process but includes your custom fields. Use Apex controllers to query the desired data and display it in a table with your custom fields.

Apex code snippet for querying PricebookEntry with custom fields:

public with sharing class ProductSelectorController {
    @AuraEnabled
    public static List<PricebookEntry> getProducts(String pricebookId) {
        return [SELECT Id, Name, Product2.Name, CustomField__c 
                FROM PricebookEntry 
                WHERE Pricebook2Id = :pricebookId];
    }
}

Code explanation:
The provided code defines an Apex class named ProductSelectorController with the with sharing keyword, ensuring that Salesforce sharing rules are respected when accessing records. It contains a static method getProducts, marked with @AuraEnabled, making it accessible from Lightning components or other Aura-enabled contexts. The method queries the PricebookEntry object, retrieving fields like Id, Name, Product2.Name, and a custom field (CustomField__c), filtering results by the Pricebook2Id passed as a parameter, which represents the specific price book.

Summing Up:

Customizing the fields displayed in the Add Products process in Salesforce involves configuring search layouts for the initial product selection screen and adjusting field sets on the PricebookEntry object for the subsequent screen. When standard options are insufficient, a custom solution, such as overriding the button with a Lightning Component or Flow, provides full control over the fields and behavior. By leveraging Apex, like the ProductSelectorController, you can dynamically query and display relevant data, ensuring your custom fields are integrated seamlessly. This approach enhances user experience while aligning with your business requirements.

Advance Your Career with Expert Salesforce Training in India

Take the next step in your career with CRS Info Solutions’ premium Salesforce training, designed to equip you with the skills needed to succeed in the dynamic Salesforce ecosystem. Our expert-led courses cover Salesforce Admin, Developer, and AI modules, providing in-depth knowledge and practical experience through real-world project scenarios. Whether you’re a beginner or an experienced professional, our structured curriculum ensures you gain the hands-on expertise needed to excel in the industry.

We focus on practical learning, offering personalized guidance, comprehensive study materials, and thorough certification preparation. Salesforce training in India Our program ensures you’re fully prepared for interviews and equipped to thrive in your Salesforce career. Don’t miss your chance to gain valuable industry insights

join our free demo class today and start your Salesforce journey with confidence! Enroll now for a free demo!

Comments are closed.