I have a list view button on Opportunity Line Items related list. I want to select multiple opp line items and then pass those ids to a visualforce page. StandardSetController does not work for opportunity line items. Please tell me what could be the possible ways to do it ?
1 Answer
Not sure if there is anything that blocks this for your case, but generally you can pass the ID values to your Visualforce page by adding a “List Button” with “Display Checkboxes” checked that has behavior “Execute JavaScript” and content source “OnClickJavaScript”:
var ids = {!GETRECORDIDS($ObjectType.OpportunityLineItem)};
if (ids.length) {
if (ids.length <= 100) {
window.location = '/apex/YourVisualforcePage?ids=' + ids.join(',');
} else {
alert('Select 100 or less');
}
} else {
alert('Select one or more Products');
}
Your controller can then access these using code such as this:
public String[] ids {
get {
if (ids == null) {
String s = ApexPages.currentPage().getParameters().get('ids');
ids = s != null ? s.split(',') : new String[] {};
}
return ids;
}
private set;
}
A bit more information here - How to pass a large number of selections from a standard list view to a Visualforce page.