I am a beginner with VisualForce pages, and a 2 week developer with SalesForce custom objects and APEX triggers/classes.

I have built a custom object called Change Request (with API name Request_for_System_Change__c), with 3 record types.

I now need to write a VisualForce page that will replicate all of the functionality of the default page, but use the styles of my org.

So I have taken the Master layout VF page provided by my org, and started to add my fields to it in the section 'Show Main data in the main panel' in the code below.

I am a little confused however about the mechanics of this.

I get that I can use <apex:outputField value= for each of the standard and custom fields in my custom object in display view, and use a form with <apex:inputField elements (with HTML <Div> and <Table> etc) and I guess I control which fields are displayed using the render attribute based on a mode variable, but how will I tell my standard controller that

  1. should I put all the fields for New/Edit and View modes on the same page
  2. How will I switch between modes?
  3. How would I tell the standard controller to show a list of exiting records and to display an existing records, edit an existing record for Update or Submit for Approval

Here is the code I have so far:

<apex:page id="CIF_Application" StandardController="Request_for_system_Change__c" 
            showHeader="false"  > 

<title>Change Requests </title>

<meta http-equiv="X-UA-Compatible" content="IE=10" />

  <apex:stylesheet value="{!URLFOR($Resource.BCSitesStyles, 'sifr3.css')}"/>
  <apex:includeScript value="{!URLFOR($Resource.BCSitesScripts, 'sifr3.js')}"/>
  <apex:includeScript value="{!URLFOR($Resource.BCSitesScripts, 'sifr-config.js')}"/>    

<apex:composition template="cif_Layout" >

<apex:define name="Title">
    Change Request1 

<apex:define name="PageStatus" >
    <apex:actionStatus startstyleClass="popupBackgroundStatusStart" stopstyleClass="popupBackgroundStatusStop"   id="MainStatustmp">
        <apex:facet name="start">
            <apex:image value="{!$Resource.AjaxIcon}" />


<!-- ------------------------------------------------------------ -->
<!-- Top Horizontal Menu  -->
<!-- ------------------------------------------------------------ -->
<apex:define name="NavTool" >

        <apex:outputpanel id="NavPanel" rendered="true">
        <div id="TopToolBar" style="margin-left: -20px">    
        <apex:actionStatus startstyleClass="popupBackgroundStatusStart" stopstyleClass="popupBackgroundStatusStop"   id="NavStatus" />

            <c:cCif_Application_Navbar />               

<!-- ------------------------------------------------------------ -->
<!-- Side bar Navigation section (show Stage of the Application) -->
<!-- ------------------------------------------------------------ -->
<apex:define name="SideBar_Navigation">
    <c:cCIF_Application_Sidebar ActiveNavOption="1" mode="Console"/> 

<!-- ------------------------------------------------------------ -->
<!-- Side bar Messages section (show Messages of the Application) -->
<!-- ------------------------------------------------------------ -->
<apex:define name="SideBar_Messages">
    <c:cCif_User_Info_Panel />  

<!-- ------------------------------------------------------------ -->
<!-- Shows Customer Name and Application Number top left of main Panel -->
<!-- ------------------------------------------------------------ -->
<apex:define name="Customer_Application_Name">


<!-- ------------------------------------------------------------ -->
<!-- Show Main data in the main panel -->
<!-- ------------------------------------------------------------ -->
<apex:define name="Main_Panel">
        <div class="mainpanelwidget OneMainPanel MainPanelTitlePadding" style="padding-right: 10px;">
    <table border="" style="width:100%; padding:3px" >
            <font class="bocTextBold">Service Announcements</font>


    <apex:pageBlock title="Basic information">

        <apex:pageMessages />
        <apex:pageBlockSection columns="1"  >
            <apex:outputField value="{! Request_for_System_Change__c.Request_Title__c }"/>
            <apex:outputField value="{! Request_for_System_Change__c.RecordTypeId }"/>
            <!--apex:outputField value="{! Request_for_System_Change__c.Owner }"/-->
            <apex:outputField value="{! Request_for_System_Change__c.Status__c }"/>
            <apex:outputField value="{! Request_for_System_Change__c.Request_Priority__c }"/>
            <apex:outputField rendered="{!Request_for_System_Change__c.Request_Priority__c=='High'}"
                              value="{! Request_for_System_Change__c.Reason_for_High_priority__c }"/>
        <apex:pageBlockSection columns="2"  >
             <apex:outputField value="{! Request_for_System_Change__c.Department_Requested_by__c }"/>
            <apex:outputField value="{! Request_for_System_Change__c.Description_of_change_requested__c }"/>
             <apex:outputField value="{! Request_for_System_Change__c.Reason_for_data_request__c }"/>
            <apex:outputField value="{! Request_for_System_Change__c.Systems_Affected__c }"/>
            <apex:outputField value="{! Request_for_System_Change__c.Manager__c }"/>
            <apex:outputField value="{! Request_for_System_Change__c.Date__c }"/>
             <apex:outputField value="{! Request_for_System_Change__c.Are_Customers_affected_by_this_change__c }"/>
            <apex:outputField value="{! Request_for_System_Change__c.Additional_information_comments__c }"/>
 <apex:outputField value="{! Request_for_System_Change__c.Benefits_Reasons__c }"/>
            <apex:outputField value="{! Request_for_System_Change__c.New_data_to_be_captured__c }"/>
 <apex:outputField value="{! Request_for_System_Change__c.Legal_Regulatory_Compliance_impact__c }"/>
            <apex:outputField value="{! Request_for_System_Change__c.Related_Committee_paper_or_action_point__c }"/>                      
<apex:pageblocksection columns="1" id="pbs1" rendered="{!Request_for_System_Change__c.recordType == 'System Change Request'}">
     <apex:detail />

<!-- ------------------------------------------------------------ -->
<!-- Show buttons for the page -->
<!-- ------------------------------------------------------------ -->
<apex:define name="Control_Panel">

    <!-- PUT BUTTONS IN HERE -->



  • 1
    did you try apex:inlineEdit component under your pageBlockSection to allow users to double click outputFields and edit the values? – cropredy Dec 17 '15 at 19:52

I would recommend using FieldSets for your section layouts and perhaps add a toggle-able field widget:

    <apex:attribute type="sObject" name="record" required="true"
        description="Record for which to display data" />
    <apex:attribute type="String" name="field" required="true"
        description="Field for which to display data" />
    <apex:attribute type="String" name="label" required="true"
        description="Label to display" />
    <apex:attribute type="Boolean" name="isEdit" default="false"
        description="Whether or not the field should be editable />

    <apex:outputLabel value="{!label}" />
    <apex:inputField rendered="{!isEdit}" value="{!record[field]} />
    <apex:outputField rendered="{!NOT(isEdit)}" value="{!record[field]} />

Then in your View page:

    <apex:repeat var="field"
                field="{!field}" label="{!field.Label}" />

You would need to use a separate page for New and Edit and set the isEdit property to true.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.