• Chris Young 2
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies

Hi everyone,

I have a Visualforce page that uses a wrapper class to allow a user to see a list of equipment items available for purchase, check items from that list, press an 'add to order' button at the bottom of the list, then the checked items in the list are moved down to a table. I want to be able to save this list of checked items as a new purchase order consisting of these items.

Here is what I have so far:

Visualforce Page:
 
<apex:page controller="AccountSelectClassController">
<script type="text/javascript">
        function selectAllCheckboxes(obj,receivedInputID){
            var inputCheckBox = document.getElementsByTagName("input");
            for(var i=0; i<inputCheckBox.length; i++){
                if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){
                    inputCheckBox[i].checked = obj.checked;
                }
            }
        }
    </script>
<apex:form >
<apex:pageBlock >
    <apex:pageBlockSection showHeader="True" title="Purchase Items" columns="1">
                           
            <apex:pageBlockTable value="{!wrapPurchaseItemList}" var="accWrap" id="table">
                    <apex:column >
                        <apex:facet name="header">
                            <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
                        </apex:facet>
                        <apex:inputCheckbox value="{!accWrap.selected}" id="inputId"/>
                    </apex:column>
                    <apex:column value="{!accWrap.acc.Description__c}" />
                    <apex:column value="{!accWrap.acc.Price__c}" />
                    <apex:column value="{!accWrap.acc.name}" />
                </apex:pageBlockTable>
            <apex:CommandButton value="Add to Order" action="{!processSelected}" rerender="requisitionitems" />
            
        
     </apex:pageBlockSection>
     <apex:pageBlockSection showHeader="True" title="Requisition Items" columns="1">
        
            
             <apex:pageBlockTable value="{!selectedPurchaseItems}" var="c" id="requisitionitems" title="Selected Accounts">
                    <apex:column id="Description" value="{!c.Description__c}" headerValue="Description"/>
                    <apex:column id="Price" value="{!c.Price__c}" headerValue="Price"/>
                    <apex:column id="Item_Code" value="{!c.name}" headerValue="Item Code"/>
                </apex:pageBlockTable>
            <apex:CommandButton value="Save" action="{!save}" />
           
               
     </apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

Apex Class:
 
public class AccountSelectClassController{
 
    //Our collection of the class/wrapper objects wrapAccount
    public List <Purchase_Item__c> poitemList {get;set;}
    public List <Purchase_Item__c> addPOItemList {get;set;}
    public List <Purchase_Item__c> delPOItemList {get;set;}
    public List <Purchase_Item__c> delPOItems {get;set;}
    public Integer totalCount {get;set;}
    public List<wrapPurchaseItem> wrapPurchaseItemList {get; set;}
    public List<Purchase_Item__c> selectedPurchaseItems{get;set;}
    public void AddPOItems(ApexPages.StandardController controller) {
                purchords = (Purchase_Order__c) controller.getRecord();
                poitemList = [Select id, Description__c, Item_Code__c, Price__c, Purchase_Order__c, Vendor__c from Purchase_Item__c where Purchase_Order__c = : purchords.Id];
                totalCount = poitemList.size();
                delPOItemList = new List < Purchase_Item__c > ();
                delPOItems = new List < Purchase_Item__c > ();
                
        }
    public AccountSelectClassController(){
        if(wrapPurchaseItemList == null) {
            wrapPurchaseItemList = new List<wrapPurchaseItem>();
            for(Purchase_Item__c a: [select Id, Description__c,Price__c, name from Purchase_Item__c limit 10]) {
                // As each Account is processed we create a new wrapAccount object and add it to the wrapAccountList
                wrapPurchaseItemList.add(new wrapPurchaseItem(a));
            }
        }
    }
 
    public void processSelected() {
    selectedPurchaseItems = new List<Purchase_Item__c>();
 
        for(wrapPurchaseItem wrapPurchaseItemObj : wrapPurchaseItemList) {
            if(wrapPurchaseItemObj.selected == true) {
                selectedPurchaseItems.add(wrapPurchaseItemObj.acc);
            }
        }
    }
   
    public Purchase_Order__c purchords;
    
    public PageReference save() {
                upsert selectedPurchaseItems;
                
                //return (new ApexPages.StandardController(purchreqs)).view();
                PageReference pageRef = new PageReference('/apex/PurchaseItemList');
                pageRef.getParameters().put('id',purchords.Id);
                return pageRef;
        }

    // This is our wrapper/container class. In this example a wrapper class contains both the standard salesforce object Account and a Boolean value
    public class wrapPurchaseItem {
        public Purchase_Item__c acc {get; set;}
        public Boolean selected {get; set;}
 
        public wrapPurchaseItem(Purchase_Item__c a) {
            acc = a;
            selected = false;
        }
    }
}
Thanks in advance!

 
Hi All,

I am trying to create a Visualforce page that contains two PageBlockTables. One of these tables contains equipment items with relevant information. On each row of this table, there is a "Quantity" input box. The other table is underneath that one, and it starts out with no data. I would like to be able to type in a quantity in the input boxes, then click a button under the table labeled "Add to Order". When this button is clicked, I would like for the equipment with input quantities to show up on the second table, where I will then place a "Save" button to save this particular selection of equipment and quantities as an iteration of a custom object. Any help for a starting point would be greatly appreciated, even if it's just a point in the right direction.

Thanks in advance!
Hi All,

I am trying to create a Visualforce page that contains two PageBlockTables. One of these tables contains equipment items with relevant information. On each row of this table, there is a "Quantity" input box. The other table is underneath that one, and it starts out with no data. I would like to be able to type in a quantity in the input boxes, then click a button under the table labeled "Add to Order". When this button is clicked, I would like for the equipment with input quantities to show up on the second table, where I will then place a "Save" button to save this particular selection of equipment and quantities as an iteration of a custom object. Any help for a starting point would be greatly appreciated, even if it's just a point in the right direction.

Thanks in advance!