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 

Controller Extension Help

Not a coder and have got some great help from the dev community providing a wireframe for me to fill in the blanks (thanks). However, with a custom controller I can't use standard list handling and severely complicates things. 

Can anyone point me in the right direction? I need standard functionality for buttons & show list views at the top of the page, but the only "custom" controlling I need is a section with rows at the bottom with an "add row" function (as well as edit/delete rows) to create child records. I was told this is an "extension" class. But I dont knwo the first thing about creating it. Take a look at the VF Page, Current Custom Controller, and the Test class. 

Let me know how you'd adjust it, and if you're able (i'd really appreciate), some code examples. Thank you! 
 

Heres the code I have NOW:

VISUALFORCE PAGE

<apex:page controller="SampleController" showHeader="True" tabstyle="Sample_Order__c">
                                                                         
    <apex:form >
        <apex:sectionHeader title="Sample Order"></apex:sectionHeader>
        <apex:pageBlock title="Sample Order Edit" mode="edit">

<!--SAMPLE ORDER RECORD SECTION & FIELDS-->  
            
			<apex:pageBlockSection title="Sample Order Information" collapsible="false" columns="2">              
                	<apex:inputField label="Project Name" value="{!sampleOrder.Project_Name__c}" required="true"/>
                	<apex:inputfield label="Order Status" value="{!sampleOrder.Status__c}" required="false"/>
                	<apex:inputField label="Sales Rep" value="{!sampleOrder.McGrory_Sales_Rep__c}" required="true" />
                	<apex:outputfield label="Order Date" value="{!sampleOrder.Request_Date__c}"/>
                	<apex:inputField label="Ship To" value="{!sampleOrder.Ship_To__c}" required="true"/>
                	<apex:inputfield label="Ship Date" value="{!sampleOrder.Ship_Date__c}" required="false"/>
                	<apex:inputField label="Notes" value="{!sampleOrder.Notes__c}" required="false"/> 
            </apex:pageBlockSection>
                        
            <apex:pageBlockSection title="Customer Information" collapsible="false" columns="2">
                	<apex:inputfield label="Company" value="{!sampleOrder.Company__c}" required="True"/>
                	<apex:outputfield label="Address" value="{!sampleOrder.Address__c}"/>
                	<apex:inputfield label="Contact" value="{!sampleOrder.Contact__c}" required="True"/>
               		<apex:inputfield label="Contact Phone" value="{!sampleOrder.Contact_Phone__c}"/>
                	<apex:inputField label="Contact Email" value="{!sampleOrder.Contact_Email__c}"/>
            </apex:pageBlockSection>
            
            <apex:pageBlockSection title="Alternate Contact Information - If Not Shipping To Sales Rep Or Customer" collapsible="True" columns="2">
                	<apex:inputfield label="Alternate Company" value="{!sampleOrder.Alternate_Company__c}" required="False"/>
                	<apex:inputfield label="Street Address" value="{!sampleOrder.Street_address__c}" required="False"/>
                	<apex:inputfield label="Alternate Contact" value="{!sampleOrder.Alternate_Contact__c}" required="False"/>
                	<apex:inputfield label="City" value="{!sampleOrder.City__c}" required="False"/>
                	<apex:inputfield label="Alternate Phone" value="{!sampleOrder.Alternate_Phone__c}" required="False"/>
                	<apex:inputfield label="State" value="{!sampleOrder.State__c}" required="False"/>
                	<apex:inputfield label="Alternate Email" value="{!sampleOrder.Alternate_Email__c}" required="False"/>
                	<apex:inputfield label="Zip/Postal Code" value="{!sampleOrder.Zip_Postal_Code__c}" required="False"/>               	              
            </apex:pageBlockSection>
            
<!--SAMPLE ORDER LINE ITEMS TABLE-->
            <apex:pageBlockSection title="Sample Order Line Items">
                <apex:pageBlockTable id="tblLineItems" value="{!sampleOrderLineItems}" var="soli">
                    <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.Width__c}"></apex:inputField>
                        <apex:facet name="header">
                            Width
                        </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.Product_Code__c}"></apex:inputField>
                        <apex:facet name="header">
                            Product Code
                        </apex:facet>
                    </apex:column>
                    <apex:facet name="footer">
                        <apex:commandButton value="Add Line" immediate="true" action="{!addLineItem}" rerender="tblLineItems"></apex:commandButton>
                    </apex:facet>
                </apex:pageBlockTable>
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
                <apex:commandButton value="Cancel" action="{!cancel}" immediate="true" html-formnovalidate="formnovalidate"/>
                <apex:commandbutton value="Edit" action="{!edit}" immediate="true" html-formnonvalidate="formnonvalidate"/>
                               
            </apex:pageBlockButtons>
            
        </apex:pageBlock>
    </apex:form>
     <apex:listViews type="Sample_Order__c" rendered="True"/> 
</apex:page>


Controller (Current, custom)​

public class SampleController {
    public Sample_Order__c sampleOrder  { get; set; }
    public List<Sample_Order_Line_Items__c> sampleOrderLineItems     { get; set; }
    
    public SampleController() {
        sampleOrder             = new Sample_Order__c();
        sampleOrderLineItems    = new List<Sample_Order_Line_Items__c>{ new Sample_Order_Line_Items__c() };
    }
    
    public void addLineItem() {
        sampleOrderLineItems.add( new Sample_Order_Line_Items__c() );
    }
    
    public PageReference save() {
        INSERT sampleOrder;
        
        for( Sample_Order_Line_Items__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' );
    }
    
    public boolean editSection {get;set;}
    {
        
    }
    public PageReference edit(){
        editSection = true;
        return null;
    }
    
}


Test Class​

@isTest 
public class SampleController_UT 
{
 static testMethod void testMethod1() 
 {
 Account oAccount = new Account();
 oAccount.name = 'Test';
 oAccount.Type = 'Architect';
 oAccount.Phone = '(856)739-2546';
 oAccount.BillingStreet = '1400 Grandview Avenue';
 oAccount.BillingCity = 'Paulsboro';
 oAccount.BillingStateCode = 'NJ';
 oAccount.BillingPostalCode = '08066';
 oAccount.BillingCountry = 'United States';
     insert oAccount;
     
 Project__c oProject = new Project__c();
 oProject.Account__c = oAccount.Id;
 oProject.Name = 'TestProject';
 oProject.Estimated_Project_Value__c = 1;
 oProject.Estimated_Completion_Date__c= date.today();
 oProject.Project_Manager__c = oAccount.CreatedById;
 oProject.Product_Type__c = 'Acid Etch';
     insert oProject;
 
 
 Sample_Order__c  oSampleOrder = new Sample_Order__c ();
 oSampleOrder.Project_Name__c = oProject.id;
 oSampleOrder.McGrory_Sales_rep__c = oProject.CreatedById;
 oSampleOrder.Ship_To__c = 'Customer';
     
 list<Sample_Order_Line_Items__c> lstSampleOrderLineItems = new list<Sample_Order_Line_Items__c>();
 Sample_Order_Line_Items__c oSampleOrderLineItems = new Sample_Order_Line_Items__c();
 oSampleOrderLineItems.Quantity__c = 1;
 oSampleOrderLineItems.Description__c = 'Test';
 //Add your required field
 lstSampleOrderLineItems.add(oSampleOrderLineItems);
 
 
 Test.StartTest(); 

  PageReference pageRef = Page.SampleOrder; // Add your VF page Name here
  Test.setCurrentPage(pageRef);

  SampleController  oSampleController  = new SampleController ();
  oSampleController.sampleOrder  = oSampleOrder;
  oSampleController.sampleOrderLineItems = lstSampleOrderLineItems; 
  oSampleController.save();
  oSampleController.cancel();
  oSampleController.addLineItem();  
 Test.StopTest();
 }
}
Alain CabonAlain Cabon
Hi,

Could you copy/paste your current result on the screen? Did you have any help from other forums?

Detail/list forms are not easy things to do in Salesforce VFP if the list can have thousands of rows but there are some tricks for the pagination.

With other tools, it is easy to do like with Oracle APEX with just "'point and click".

Oracle APEX (Application Express) : http://o7planning.org/en/10419/oracle-apex-master-details-tutorial

User-added image

You want to code a form resembling a little this form?

A global button "Save" (or global Delete) for the order and its order items and two buttons "Delete checked" and "Add Row" for the order items.

Best regards
Alain