So I'm trying to build some custom functionality revolving around opportunities and products.

What I have right now is a button on the OpportunityLineItem related list that is on our opportunities. When a user presses that button they are brought to a custom visualforce page with the same opp line items that are on the opportunity. From there, users can change a specific field on each of these that laucnhes some custom code.

What I really want though, is for only one selected item to be brought over to the visualforce page. I want to let users select that item with the action checkboxes on the opportunity line items.

Here's what I'm talking about:

select line item

So my question is: how can I tell what item is selected, and dictate my visualforce to only display that line item? I can't find anything in the API referncing these selection boxes, but I'm sure there must be something.

Here's the current state of my visualforce page:

<apex:page standardController="Opportunity" extensions="Opportunity_extendedController" >
<apex:pageBlock title="Line Items">
    <apex:form >
        <apex:commandButton action="{!exchangeInv}" value="Exchange Inventory" rerender="fake" />
        <apex:commandButton action="{!cancel}" immediate="true" value="Cancel"/>
        <apex:pageBlockTable value="{!Opportunity.opportunityLineItems}" var="oli">
            <apex:column value="{!oli.Id}" />
            <apex:column value="{!oli.Inventory__c}"/>
            <apex:column value="{!oli.Name_Description__c}"/>
            <apex:column headerValue="Inventory to exchange">                
                <apex:inputField value="{!oli.Inventory__c}" />

  • I was writing up an answer using a List Controller, but, when I tried to save my example, Salesforce gave me an error saying that "List Controllers are not supported for OpportunityLineItem". Yet another WTF Salesforce moment for me... I think you may be out of luck trying to figure out precisely which OLIs were selected in the related list (even with a StandardSetController, you couldn't restrict how many OLIs a user could select, nor reliably tell the order in which they were selected).
    – Derek F
    Commented Aug 3, 2017 at 14:15

2 Answers 2


If you don't have any solution then I have a work around for this if you want to try. Below is the code for that

You can either use cookies to set value and then retrieve in your VF page or you can pass the value in URL. Below is the example of passing value to URL.

var allProducts = document.getElementsByName('ids');
            var str = '';
            for(var i=0; i<allProducts.length; i++){
                    str += allProducts[i].value + '-';

Visual force Page

    <apex:page standardController="opportunity" recordSetVar="opportunitylineItems" extensions="ShowOppLineItemsController">
        <apex:pageBlockTable value="{!LineItems}" var="Item">
            <apex:column value="{!Item.product2.name}"/>

Apex Class

public class ShowOppLineItemsController{

    //List to display on page
    public list<opportunityLineItem> LineItems{get;set;}

    //Standard set controller
    public ShowOppLineItemsController(ApexPages.StandardSetController controller){
        LineItems = new list<opportunityLineItem>();
        list<string> allIdsList = new list<string>();

        //Getting ids from the url
        string AllIds = apexpages.currentpage().getparameters().get('AllIds');
        if(AllIds != null && AllIds != ''){
            //Spliting all ids in list to make a query
            allIdsList = AllIds.split('-');
            if(allIdsList != null && allIdsList.size() > 0){
                //final query on line items
                LineItems = [select id, name, product2.name from opportunityLineItem where id In : allIdsList];

  • Oh nice I never even thought of doing it this way, the javascript is grabbing the correct elements. However, I'm having some trouble actually getting those line items to appear on the visualforce page. By adding my line item IDs onto the end of that URL, I just end up with an empty table on my visualforce page. How can I change my visualforce markup to accept the items I want to display from the URL like this?
    – Adam O.
    Commented Aug 3, 2017 at 17:53
  • you know have to use controller side to take all the line items ids and make a query and then finally display on the table. Commented Aug 3, 2017 at 18:08
  • Okay gotcha, I'm kind of new to visualforce and custom controllers, could you direct me to some documentation on doing something like this?
    – Adam O.
    Commented Aug 3, 2017 at 19:09
  • Please use the salesforce docs to go through them. Here is the link developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/…. Also I am adding another answer with full code below to your reference , If you find it helpful please select it as a best answer Commented Aug 4, 2017 at 5:49

Let's do this task as following (you can improvise the solution)

  1. Use javscript button and put it in the related list as stated
  2. On button click you can get the list of selected items (I believe this still works with button JS)
  3. Once you have refined the list of items, form the next page URL (I mean VF page URL)
  4. All I am trying to convey is that, use URL param to pass those selected values and use them as you wanted.
  • Do you know how I would get that list of selected items with JS? I can't find anything that references the status of their selection.
    – Adam O.
    Commented Aug 3, 2017 at 14:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .