[SalesForce] Visualforce page loaded with items selected from a related list

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}" />
            </apex:column>
        </apex:pageBlockTable>
    </apex:form>
</apex:pageBlock>

Best Answer

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++){
                if(allProducts[i].checked){
                    str += allProducts[i].value + '-';
                }
            }
    window.open('/apex/PageName?AllIds='+str);

Visual force Page

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

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];
            }
        }
    }

}
Related Topic