Customizing and integrating Salesforce is essential in all implementation projects. In this article, we’re going to show how ‘URL redirection’ can help you achieve desired results.
Consider a business scenario where a company ‘ABC’ is having a huge number of Products and Customers. Products are items or services for which customers can create an opportunity for. Products need to be selected by the customer in order to create an ‘Opportunity’. However, not all products may be active at the time of opportunity creation. Some products may be inactive, either permanently or for specific period. By default, Salesforce has opportunity object within which a related related object called ‘Opportunity Products’ is present. When salesperson add line items to Opportunities it is in this object that that details get captured. The adding of line items is done by a default button called ‘Add Product’ within the same, which lists all the products existing in ‘Product’ module without considering whether it’s active or inactive.
Because of this, there are chances for a customer to create an opportunity with inactive products. To avoid this scenario, we need to provide a way to list only Active products while creating an opportunity.
No need to worry, we can handle this through ‘URL redirection’.
The below process shows how to list only ‘Active Products’ in Opportunity Products so that, Customer can select only the ‘Active’ Products. The process includes creating a ‘Custom Button’ and provide a ‘URL’ to which redirection needs to be done.
Create Custom Button:
- Navigate to Set up–> Build -> Customize -> Opportunities –> Opportunity Product–> Button and Links. As shown in the below screenshot
- Click on the Button ‘NewButton or Link’ as shown below
- Provide the details as shown below
- Label : Add Product
- Display Type : Select the display type based on your requirement
- I want to display as ‘List Button’ so, I’m selecting ‘List Button’
- I need to select multiple products at a time. So, I’ve checked ‘Display Checkboxes’ checkbox
- Behavior : I want to display it in the same page without sidebar or header.
- So, I’m select ‘Display in existing window without sidebar or header’
- Content Source: I’m taking content from ‘URL’. So, I’ve selected ‘URL’ from list
URL Formation:
Now you’ve to provide the URL to which you’ve to redirect. You can get the URL by following the steps given below
- Navigate to ‘Opportunity Product Add’ Page
- Copy the URL after ‘https://ap5.salesforce.com’ as shown in the below screen
- This is the URL which I’ve copied from ‘Opportunity Product Add’ page
‘/p/opp/SelectSearch?addTo=0067F000008kCkj&retURL=%2F0067F000008kCkj’
- Now, replace ‘0067F000008kCkj’ in the above ‘URL’ with ‘{!Opportunity.Id}’
- Below is the URL after replacement
‘/p/opp/SelectSearch?addTo={!Opportunity.Id}&retURL=%2F{!Opportunity.Id}’
- After replacing the URL, you need to provide the following details:
- PricebookEntrycol0=PRODUCT2.ACTIVE
- PricebookEntryoper0=e
- PricebookEntryfval0=True
- To get these details, navigate to ‘Find Products’ tab and do inspect element on ‘By Field Filter’ list as shown in the below screen
- All the fields existing in the product module will be listed there. Select the field based on your requirement.
- Here I’m selecting ‘Active’ checkbox in Product (PRODUCT2.ACTIVE) and its value is ‘true’ (PricebookEntryfval0=True)
- In the same way, you can add any number of conditions based on your requirement.
- This is the resultant URL after combining all the details collected above
‘/p/opp/SelectSearch?addTo={!Opportunity.Id}&retURL=%2F{!Opportunity.Id}&&&&PricebookEntrycol0=PRODUCT2.ACTIVE&PricebookEntryoper0=e&PricebookEntryfval0=True’
- Now, Copy this URL in the text area given below and check for syntax errors if any. Click on ‘Save’ in case of no errors.
- Below screen shows the resultant ‘Custom Button’
- In this way, we can avoid Inactive Products while creating ‘Opportunity’.
Now, when a customer is adding an ‘Opportunity Product’, Customer can only see the ‘Active’ Products by clicking on ‘Add Product’ Button.
In this way, we can use ‘URL Redirection’ to display on ‘Active’ Products in ‘Opportunity Products’ module.
You can use this functionality in other business cases as well. The good thing about this is that you do not have to use custom APEX code to achieve your objectives. Hope this guide was useful. Comments and feedback are welcome as always.