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
dlCamelotdlCamelot 

Request Form with Custom Controller

I'm trying to create a form submission page (see VF below) that creates a new record with a custom controller (see Controller below) on my custom object = Enhancement Request.     Could someone figure out the gap in execution here?  

Bonus points:
1) I need to render visualforce blocks based on 'showConfirmation' variable; it should be TRUE when no error messages are present.  

CONTROLLER:

public with sharing class EnhancementRequestControllerv2 {
    /*  New Request */
  public Enhancement_Request__c er {
      get {
          if (er == null)
              er = new Enhancement_Request__c();
                er.Form_Channel__c = TRUE;
          return er;
      }
      set;
  }
   Public string CurrentUserId{get;set;}
   Public String CurrentUserEmailId{get;set;}
   Public String CurrentUserName{get;set;}

   public EnhancementRequestControllerv2(){
            CurrentUserId = userinfo.getuserid();
            CurrentUserEmailId = userinfo.getUserEmail(); 
            CurrentUserName = userinfo.getName();

    }
    */
 
        
    /*Save new record*/
    public PageReference submitRequest() {
     
        
        try{
            insert er;
               }
            catch(DmlException ex){
            ApexPages.addMessages(ex);
             
            }
        return null;  
    }
   
}
*******************************************************************************************************************************************************

VISUALFORCE PAGE

<apex:page controller="EnhancementRequestControllerv2"
           cache="false"
  showHeader="false"
  sidebar="false"
    title="Enhancement Request">

<html>
<head>
<title>Enhancement Request</title>
<style>
span.pbSubExtra {
  display: none;
}
input.instructions{
  margin: 10px; 
  width: 100%;
  text-align: left;
  margin-left: auto;
  margin-right: auto;
}
input.labels{
  margin: 10px;
  width: 100%;
  text-align: right;
  margin-left: auto;
  margin-right: auto;
  font-weight:bold
}
</style>
</head>
<body>
<apex:image id="logo" value="{!$Resource.logo}" /> 

<div style="width: 700px; margin-left: 5px;">
<apex:form >

  <apex:pageMessages />
  
  <apex:pageBlock id="thePB" mode="edit" rendered="{!NOT(showConfirmation)}" >

    <!-- main form section -->
    <apex:pageBlockSection collapsible="false" columns="1" title="Enhancement Submission Form">
          <!-- instructions -->
          <apex:pageBlockSectionItem >
              <apex:outputPanel layout="block" styleClass="instructions">
                  <apex:outputLabel value="What is your request for the team?"  />
              </apex:outputPanel>
          </apex:pageBlockSectionItem>
         <!-- inputs -->
           <apex:pageBlockSectionItem >  
              <apex:outputLabel value="{!$ObjectType.Enhancement_Request__c.Fields.Request_Type__c.Label}"  />
              <apex:inputField value="{!er.Request_Type__c}" style="width: 350px; height: 30px;" />   
           </apex:pageBlockSectionItem>  
           
           <apex:pageBlockSectionItem >  
              <apex:outputLabel value="{!$ObjectType.Enhancement_Request__c.Fields.Details__c.Label}"  />
              <apex:inputField value="{!er.Details__c}" style="width: 350px; height: 75px;" />
           </apex:pageBlockSectionItem> 
           <br/>
          <!-- instructions part2 -->
          <apex:pageBlockSectionItem >
              <apex:outputPanel layout="block" styleClass="instructions">
                  <apex:outputLabel value="The following account will receive notifications regarding this request."  /><br/>
              </apex:outputPanel>
           </apex:pageBlockSectionItem>
           <!-- submitter details -->  
           <apex:pageBlockSectionItem >
              <apex:outputPanel layout="block" styleClass="label">
                 <apex:outputLabel value="Submitter Name"/>
              </apex:outputPanel>
              <apex:outputPanel layout="block" style="width: 100%; text-align: left; margin-left: auto; margin-right: auto;">
                 <apex:outputText value="{!CurrentUserName}"/><br/>
              </apex:outputPanel>
           </apex:pageBlockSectionItem>
           <apex:pageBlockSectionItem >
              <apex:outputPanel layout="block" styleClass="label">
                 <apex:outputLabel style="font-weight:bold" value="Submitter Email"/>
              </apex:outputPanel>
              <apex:outputPanel layout="block" style="width: 100%; text-align: left; margin-left: auto; margin-right: auto;">
                 <apex:outputText value="{!CurrentUserEmailId}"/><br/>
              </apex:outputPanel>
          </apex:pageBlockSectionItem>

    </apex:pageBlockSection>
  
    <!-- buttons section -->    
    <apex:pageBlockSection columns="1" collapsible="false" showHeader="false">
      <apex:pageBlockSectionItem >
        <apex:outputPanel layout="block" style="margin: 10px; width: 100%; text-align: center; margin-left: auto; margin-right: auto;">
          <apex:commandButton action="{!submitRequest}" value="Submit Request" />
          <apex:commandButton value="Clear" onclick="window.location.href=window.location.href; return false;"/>
        </apex:outputPanel>
      </apex:pageBlockSectionItem>
    </apex:pageBlockSection>

  </apex:pageBlock>

  <!-- confirmation message, only renders when request is submitted -->
  <apex:pageBlock mode="edit" id="pb_conf" rendered="{!showConfirmation}">
    <apex:pageBlockSection columns="1" title="Enhancement Request">
      <apex:outputPanel layout="block" style="margin-bottom: 5px;">
        Your request has been submitted and is being processed. You should receive an email confirmation regarding your submission.  
      </apex:outputPanel>
    </apex:pageBlockSection>
  </apex:pageBlock>

</apex:form>
</div>

</body>
</html>

</apex:page>
SwarnaSankhaSinghSwarnaSankhaSingh
Hi dlCamelot,

Just to confirm your requirements from this vfPage and it's associated Apex Controller:
  1. You have a custom object named Enhancement_Request__c.
  2. You are creating a custom form interface which will create new Enhancement_Request__c requests.
  3. When you click on the SubmitRequest button,
    • If there are no errors generated then you would like to show the pageBlock containing the confirmation message.
    • if there are any errors generated then it should show up the details on the top of the form with all the values on the forms as is. (I added this from my side thinking you may have wanted it but just did not mention it)
  4. You would like to control the behaviour in the earlier point using the showConfirmation variable.
My question is where have you in your controller declared and defined the logic for the showConfirmation variable? And also can you share the detail of what is the gap you are observing in the feature developed by you?

Kind Regards,
Swarna.