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
Shirish DwivediShirish Dwivedi 

Opportunity Product Entry Page Customization - Want Pre-filter on this page

Hi guys,

I have customized the Opportunity Product Entry page with the help of Michealforce.org (http://www.michaelforce.org/recipeView?id=a0G30000006eVxVEAU)

But I want to have a pre-filter (just like in Standar Opportunity Product entry page) on my custom page that would show me the results specified according to that filter.

When I should click Add Product/Service button from the opportunity page it takes me to the custom page which I used from the link above. But I want the pre-filter to be automatically set with respect to "Some Field" = True and the results should be shown according to that filter. The image below shows the filter I am talking about and the Standard SF page.
User-added image
Dilip_VDilip_V
Shirish,

Instead of doing that you can alter your search catogory.Have you noticed this in opportunityProductEntryExtension?
// note that we are looking for the search string entered by the user in the name OR description
        // modify this to search other fields if desired
        if(searchString!=null){
            qString+= ' and (Product2.Name like \'%' + searchString + '%\' or Product2.Description like \'%' + searchString + '%\')';
        }

Let me know if you have any issues.

Mark it as best answer if ot works.

Thanks.
Shirish DwivediShirish Dwivedi
Hi , thank you for taking time to look into the issue. 
The thing is the field which I want to filter for is called ProductBundle__c and it is a custom field in Product Object. 
When I changed the searchstring to this 

 if(searchString!=null){
            qString+= ' and (Product.isProductBundle__c like \'%' + searchString + '%\' or Product2.Description like \'%' + searchString + '%\')';
        }
        
I get the following error: 

Didn't understand relationship 'Product' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.

Also how would the search box give me the result of all those Product/Service Name for which isProductBundle__c is True? 
Please note that this field is a checkbox, so it returns a boolean value.

Further assitance will be highly appreciated.
Dilip_VDilip_V
Shirish,

Use product2 not Product.
Note that you have to pass either true or false to get results.
 
if(searchString!=null){
            qString+= ' and (Product2.isProductBundle__c = + searchString +  or Product2.Description like \'%' + searchString + '%\')';
        }
Let me know if you have any issues.

Mark it as best answer if ot works.

Thanks.
Thanks.
Shirish DwivediShirish Dwivedi
Hi I just did this 

public void updateAvailableList() {
    
        // We dynamically build a query string and exclude items already in the shopping cart
        String qString = 'select Id, Pricebook2Id, Product2.isProductBundle__c, IsActive, Product2.Name, Product2.Family, Product2.IsActive, Product2.Description, UnitPrice from PricebookEntry where IsActive=true and Pricebook2Id = \'' + theBook.Id + '\'';
        if(multipleCurrencies)
            qstring += ' and CurrencyIsoCode = \'' + theOpp.get('currencyIsoCode') + '\'';
        
        // note that we are looking for the search string entered by the user in the name OR description
        // modify this to search other fields if desired
        if(searchString!=null){
            qString+= ' and (Product2.isProductBundle__c= + searchString +  or Product2.Description like \'%' + searchString + '%\')';
        }

When I type true in searchbox 
But it gives me this error: 
unexpected token: 'searchString'
Error is in expression '{!updateAvailableList}' in page opportunityproductentry: Class.opportunityProductEntryExtension.updateAvailableList: line 140, column 1

Thanks
Dilip_VDilip_V
Thats a type.Missed ' '
try this
public void updateAvailableList() {
    
        // We dynamically build a query string and exclude items already in the shopping cart
        String qString = 'select Id, Pricebook2Id, Product2.isProductBundle__c, IsActive, Product2.Name, Product2.Family, Product2.IsActive, Product2.Description, UnitPrice from PricebookEntry where IsActive=true and Pricebook2Id = \'' + theBook.Id + '\'';
        if(multipleCurrencies)
            qstring += ' and CurrencyIsoCode = \'' + theOpp.get('currencyIsoCode') + '\'';
        
        // note that we are looking for the search string entered by the user in the name OR description
        // modify this to search other fields if desired
        if(searchString!=null){
            qString+= ' and (Product2.isProductBundle__c= '+ searchString + ' or Product2.Description like \'%' + searchString + '%\')';
        }

​
Let me know if you have any issues.

Mark it as best answer if ot works.

THanks.
Shirish DwivediShirish Dwivedi
Although it worked this time. But unfortunately it shows no result when I type True in the searchbox.

I am pretty sure there are products with isBundle__c= True;


but they are not showing up in the search field.
Shirish DwivediShirish Dwivedi
Is there any way I can have the same picklist as it shows in the Standard VF page? Which would allow users manually to add more filters too if required?

Any help would be highly appreciated.