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
supriya jain 27supriya jain 27 

How can we Add product based on filters on Opportunity in lightning environment

I want to display Products records with some filter conditon, when I click on Add product on Opportunities.
I have achieved it using custom vf page and URL parameters,it is working fine in Classic but this is not working in Lightning.It redirects to Classic Add product page and again after adding it navigates back to lighning. Do anyone know the work around for this So that it remains in lighning environment even at the time of adding products?
AnudeepAnudeep (Salesforce Developers) 
Hi Supriya,

A similar question was discussed here

I recommend overriding the 'Add Products' button with a Visualforce page and surface the lighting component inside the VF page to check if it remains in a lightning environment

Step 1: Create a lightning component with your custom logic (filter conditions)
 
<aura:component access="global">

Hello World in Lightning Component !!

</aura:component>

Step 2: Create a lightning Application
 
<aura:application extends="ltng:outApp" >
<c:LightningTabComp/>
</aura:application>

Step 3: Then create a VF Page
 
<apex:page standardController="Opportunity">
<apex:includeLightning />
<div id="lightning" />
<script type="text/javascript">
$Lightning.use("c:LightningTabVf", function() {
$Lightning.createComponent("c:LightningTabComp",
{},
"lightning",
function(component) {

});
});

</script>
</apex:page>

Navigate to Opportunity Products object, go to the buttons sections, and select the Add Products button and edit and override with the above VF Page

Let me know if it works with lightning out

If you find this information helpful, please mark this answer as Best. It may help others in the community. Thank You!

Anudeep
supriya jain 27supriya jain 27
Hi Anudeep,
Thanks for the reply.
User-added image
I am using a custom vf page on Opportunity Detail page, but Add product button is standard only , we just used the filters (So product are dispayed based on certain contions instead of all Products) to navigate to Add Product URL. 
 
 <script type="text/javascript">    
    function redirectAddProduct(){
        //Added for filtering Product based on Opportunity Record Type by supriya jain
       
        if (confirm("Warning! Please click cancel and verify all the fields in Opportunity, otherwise you will get validation error whiling adding products!")) {
             window.top.location.href = '/p/opp/SelectSearch?addTo={!$CurrentPage.parameters.Id}&retURL=%2F{!$CurrentPage.parameters.Id}&PricebookEntrycol0={!$Label.Knowles_Product_Division_Field_Id}&PricebookEntryoper0=e&PricebookEntryfval0={!productDivision}&PricebookEntrycol1=PRODUCT2.ACTIVE&PricebookEntryoper1=e&PricebookEntryfval1=true';
        }         
    }
    function redirectEditAll(){
        window.top.location.href = '/oppitm/multilineitem.jsp?oppId={!$CurrentPage.parameters.Id}&retURL=%2F{!$CurrentPage.parameters.Id}';
    }
    function redirectChoosePriceBook(){
        window.top.location.href = '/oppitm/choosepricebook.jsp?id={!$CurrentPage.parameters.Id}&retURL=%2F{!$CurrentPage.parameters.Id}&amp;saveURL=%{!$CurrentPage.parameters.Id}';
    }    
    </script> 


This vf is successfully visible in Lightning experience, the only problem I am facing is with Add Product URL, it If I get the URL suggesstion for lightning UI, I can use that URL in lightning component navigation.