So I used URL hack method to prepopulate the filter criteria for the Product selection Page based on a field on opportunity and here is sample controller for overriden Add Product button . For same i have used below code
public with sharing class ProductAddCtrl {
private final Opportunity opp;
public string url{get;set;}
public static final string URLCONSTANT='/p/opp/SelectSearch?addTo=';
public static final string RET_URL='&retURL=%2F';
public static final string PRICEBOOKENTRYCOL0 ='&PricebookEntrycol0=';
public static final string PRICEBOOKENTRYCONSTANTS='&PricebookEntryoper0=e&PricebookEntryfval0=';
public static final string NO_OVERRIDE_CONSTANT='&nooverride=1';
public ProductAddCtrl(ApexPages.StandardController stdController){
this.opp=(Opportunity)stdController.getRecord();
}
public pagereference redirect(){
Opportunity oppvar=[Select Id,Business_Unit__c from Opportunity where Id=:opp.Id LIMIT 1];
String url=URLCONSTANT;
url=url+oppvar.Id+RET_URL;
url=url+oppvar.Id+PRICEBOOKENTRYCOL0+Label.Product_Business_Unit_Field_Id+PRICEBOOKENTRYCONSTANTS+oppvar.Business_Unit__c+NO_OVERRIDE_CONSTANT;
pagereference p=new pagereference(url);
p.setRedirect(true);
return p;
}
}
This works well but with small glitch
The clear filter link formed after this URL hack does not clear at the top highlightedalthough it resets at bottom table .Anyone familiar with better approaches without complete Visualforce solution
Attribution to: Mohith Shrivastava
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/33716