function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
BillPowell__cBillPowell__c 

Visualforce Help Using List Handlers For A Non Developer

Hoping the dev group can help me out. 

I want to create a visualforce page for a custom object "Sample Order". Sample order simply takes a few fields of input and adds the order to a queue for my sample team to fulfill an order, and keep track of orders placed, in process, and shipped. 

On the "Sample Order" page, the complicated part I can' figure out is how to write the visualforce page to include adding multiple child records for the custom object "Sample Order Line Items" in one shot, and have them display in the related list. 

I'd like to get something like this screenshot (very rough, done in excel)

User-added image

I can create the basic parts of the vf page since its just basic inputs and lookups, but need some help on creating the custom controller and the code to handle this list. I found a bunch of articles online but none seem to do the trick. 

Any help would be appreciated, thank you! 
Shruti SShruti S
I was able to replicate this in my Org. I created a Controller for storing the values and a Visualforce page for providing a medium for entering the values.
Take a look into the code -

Apex Controller
public class SampleController {
    public Sample_Order__c sampleOrder  { get; set; }
    public List<Sample_Order_Line_Item__c> sampleOrderLineItems     { get; set; }
    
    public SampleController() {
        sampleOrder             = new Sample_Order__c();
        sampleOrderLineItems    = new List<Sample_Order_Line_Item__c>{ new Sample_Order_Line_Item__c() };
    }
    
    public void addLineItem() {
        sampleOrderLineItems.add( new Sample_Order_Line_Item__c() );
    }
    
    public PageReference save() {
        INSERT sampleOrder;
        
        for( Sample_Order_Line_Item__c soli : sampleOrderLineItems ) {
            soli.Sample_Order__c = sampleOrder.Id;
        }
        
        INSERT sampleOrderLineItems;
        
        return new PageReference( '/' + sampleOrder.Id );
    }
    
    public PageReference cancel() {
        return new PageReference( '/home/home.jsp' );
    }
}

Visualforce
<apex:page controller="SampleController">
    <apex:form >
        <apex:sectionHeader title="Mass Create Sample Order Line Items"></apex:sectionHeader>
        <apex:pageBlock title="Sample Order Edit" mode="edit">
            <apex:pageBlockSection title="Sample Order Information">
                <apex:inputField label="Name" value="{!sampleOrder.Name}" required="true"></apex:inputField>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Sample Order Line Items">
                <apex:pageBlockTable id="tblLineItems" value="{!sampleOrderLineItems}" var="soli">
                    <apex:column >
                        <apex:inputField value="{!soli.Name}"></apex:inputField>
                        <apex:facet name="header">
                            Name
                        </apex:facet>
                    </apex:column>
                    <apex:column >
                        <apex:inputField value="{!soli.Quantity__c}"></apex:inputField>
                        <apex:facet name="header">
                            Quantity
                        </apex:facet>
                    </apex:column>
                    <apex:column >
                        <apex:inputField value="{!soli.Description__c}"></apex:inputField>
                        <apex:facet name="header">
                            Description
                        </apex:facet>
                    </apex:column>
                    <apex:column >
                        <apex:inputField value="{!soli.Height__c}"></apex:inputField>
                        <apex:facet name="header">
                            Height
                        </apex:facet>
                    </apex:column>
                    <apex:column >
                        <apex:inputField value="{!soli.Width__c}"></apex:inputField>
                        <apex:facet name="header">
                            Width
                        </apex:facet>
                    </apex:column>
                    <apex:column >
                        <apex:inputField value="{!soli.Item__c}"></apex:inputField>
                        <apex:facet name="header">
                            Item
                        </apex:facet>
                    </apex:column>
                    <apex:facet name="footer">
                        <apex:commandButton value="Add Line Item" immediate="true" action="{!addLineItem}" rerender="tblLineItems"></apex:commandButton>
                    </apex:facet>
                </apex:pageBlockTable>
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"></apex:commandButton>
                <apex:commandButton value="Cancel" action="{!cancel}"></apex:commandButton>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Here is a screenshot of how it would look like -

User-added image
BillPowell__cBillPowell__c
Thank you! Will this support dynamically adding line items and create them as child objects in the related list? Also, how would I add the custom fields onto this, just the standard
Shruti SShruti S
Here is a gif which illustrates the page - User-added image

I hope this answers your question. Also could you clarify where you would like to add the custom or standard fields?
BillPowell__cBillPowell__c
Excellent! ill give this a whirl. THANK YOU very much! I owe you a beer/coffee/tea/whateverYouDrink :-)
Shruti SShruti S

No problem, happy to help. I will take the beer ;) Do let me know if you have any issues.

BillPowell__cBillPowell__c
To add, your solution did everything I needed it to do. Thanks again! I'm wrapping up testing and launching this week. Thanks!