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
AmandaSilberAmandaSilber 

VF page not showing 'saved' values

I have two custom vf pages an edit page (to input fields) and a detail page (to view the record)  I put a controller on the edit page that saves the record and then redirects to the detail page. When I click the save button, it redirects to the detail page, but there is none of the information in the page that I just input - but when I go back to the list view, the information had been saved.  I think I need to add something in the controller to place the id, but I'm not sure how.

 

I am not at all a developer and this is my first shot at a custom visualforce page as a higher level admin. I'm sorry if it's horrid or messy I am self-teaching as I go!  =(

 

Controller Extension:

 

public class NewPVal{
    ApexPages.StandardController controller;
        public NewPVal(ApexPages.StandardController con){
                controller = con;
                     }
                                      
public PageReference save()
 {        controller.save();
         return page.EmployeeValidation;
             }

public PageReference cancel()
{         controller.cancel();
          return null;
          }
          }

 Edit page:

<apex:page standardController="Partnership_Validation__c" extensions="NewPVal" showHeader="true" title="Employee Validation Edit"> 
<apex:form id="PartnershipValidation">

    <apex:pageBlock >
        <apex:facet name="header"><h1>Partnership Account Edit</h1></apex:facet>
            <br><h2><style> h2 {font-size:1.875em;}</style>{!Partnership_Validation__c.Name}</h2></br>
        <apex:pageBlockButtons location="both" >               
        <br><apex:commandButton value="Submit Validation" action="{!Save}"/> <apex:commandButton value="Cancel" action="{!Cancel}" onclick="return confirmCancel()"/></br> </apex:pageBlockButtons>
     </apex:pageBlock>
    
    <apex:pageBlock >
          <apex:pageBlockSection title="Employee Information">
               <apex:inputField value="{!Partnership_Validation__c.HLC_Name__c}"/>
               <apex:inputField value="{!Partnership_Validation__c.HLC_Status__c}"/>
               <apex:inputField value="{!Partnership_Validation__c.Partnership_Employee__c}"/>
          </apex:pageBlockSection>
    </apex:pageBlock>

<apex:actionRegion rendered="{!IF(MONTH(TODAY())= 1,true,false)}"> 
    <apex:pageBlock id="block1">
        <apex:pageBlockSection title="January Validation">
             <apex:inputField value="{!Partnership_Validation__c.Days_per_month_you_reside_at_SRA__c}"/>
             <apex:inputField value="{!Partnership_Validation__c.Partner_provided_furniture_utilized__c}">
                 <apex:actionSupport event="onchange" rerender="block1"/>
             </apex:inputField>
             <apex:inputField value="{!Partnership_Validation__c.Type_of_space_you_occupy__c}"/>
             <apex:inputField value="{!Partnership_Validation__c.Other_Furniture__c}" rendered="{!IF(CONTAINS(Partnership_Validation__c.Partner_provided_furniture_utilized__c, 'Other (indicate other below)'),true,false)}"/>
             <apex:inputField value="{!Partnership_Validation__c.Size_of_the_space_you_occupy_sqft__c}"/>  
         </apex:pageBlockSection>
     </apex:pageBlock>
</apex:actionRegion> 

<apex:actionRegion rendered="{!IF(MONTH(TODAY())= 1,true,false)}">
    <apex:pageBlock id="block2"> 
        <apex:pageBlockSection title="February Validation">   
              <apex:inputField value="{!Partnership_Validation__c.Citi_Issued_Equiptment__c}"/>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:actionRegion>
  
<apex:actionRegion rendered="{!IF(MONTH(TODAY()) = 1,true,false)}"> 
    <apex:pageBlock id="block3">
        <apex:pageBlockSection title="March Validation">   
              <apex:inputField value="{!Partnership_Validation__c.Choose_customer_disclosures_displayed__c}">
              <apex:actionSupport event="onchange" rerender="block3"/>
                    </apex:inputField>
              <apex:inputField value="{!Partnership_Validation__c.Specify_Other_Disclosures__c}" rendered="{!(Partnership_Validation__c.Choose_customer_disclosures_displayed__c = "Other")}"/>        
         </apex:pageBlockSection>
    </apex:pageBlock>
</apex:actionRegion>
                
<apex:actionRegion rendered="{!IF(MONTH(TODAY()) = 1,true,false)}"> 
    <apex:pageBlock id="block4" >
        <apex:pageBlockSection title="April Validation">
             <apex:inputField value="{!Partnership_Validation__c.Days_per_month_you_reside_at_SRA__c}"/>
             <apex:inputField value="{!Partnership_Validation__c.Partner_provided_furniture_utilized__c}">
                 <apex:actionSupport event="onchange" rerender="block4"/>
             </apex:inputField>
             <apex:inputField value="{!Partnership_Validation__c.Type_of_space_you_occupy__c}"/>
             <apex:inputField value="{!Partnership_Validation__c.Other_Furniture__c}" rendered="{!(Partnership_Validation__c.Partner_provided_furniture_utilized__c = "Other (indicate other below)")}"/>
             <apex:inputField value="{!Partnership_Validation__c.Size_of_the_space_you_occupy_sqft__c}"/>  
         </apex:pageBlockSection>
    </apex:pageBlock> 
</apex:actionRegion>

<apex:actionRegion rendered="{!IF(MONTH(TODAY()) = 1,true,false)}"> 
    <apex:pageBlock id="block5">
        <apex:pageBlockSection title="May Validation">   
              <apex:inputField value="{!Partnership_Validation__c.Citi_Issued_Equiptment__c}"/>
      </apex:pageBlockSection>
    </apex:pageBlock>
</apex:actionRegion>
  
<apex:actionRegion rendered="{!IF(MONTH(TODAY()) = 1,true,false)}"> 
    <apex:pageBlock id="block6">
        <apex:pageBlockSection title="June Validation">   
              <apex:inputField value="{!Partnership_Validation__c.Choose_customer_disclosures_displayed__c}">
              <apex:actionSupport event="onchange" rerender="block6"/>
                    </apex:inputField>
              <apex:inputField value="{!Partnership_Validation__c.Specify_Other_Disclosures__c}" rendered="{!(Partnership_Validation__c.Choose_customer_disclosures_displayed__c = "Other")}"/>        
         </apex:pageBlockSection>
    </apex:pageBlock>
</apex:actionRegion>
  
<apex:actionRegion rendered="{!IF(MONTH(TODAY()) = 1,true,false)}"> 
    <apex:pageBlock id="block7" >
        <apex:pageBlockSection title="July Validation">
             <apex:inputField value="{!Partnership_Validation__c.Days_per_month_you_reside_at_SRA__c}"/>
             <apex:inputField value="{!Partnership_Validation__c.Partner_provided_furniture_utilized__c}">
                 <apex:actionSupport event="onchange" rerender="block1"/>
             </apex:inputField>
             <apex:inputField value="{!Partnership_Validation__c.Type_of_space_you_occupy__c}"/>
             <apex:inputField value="{!Partnership_Validation__c.Other_Furniture__c}" rendered="{!(Partnership_Validation__c.Partner_provided_furniture_utilized__c = "Other (indicate other below)")}"/>
             <apex:inputField value="{!Partnership_Validation__c.Size_of_the_space_you_occupy_sqft__c}"/>  
         </apex:pageBlockSection>
    </apex:pageBlock> 
</apex:actionRegion>

<apex:actionRegion rendered="{!IF(MONTH(TODAY()) = 1,true,false)}"> 
    <apex:pageBlock id="block8">
        <apex:pageBlockSection title="August Validation">   
              <apex:inputField value="{!Partnership_Validation__c.Citi_Issued_Equiptment__c}"/>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:actionRegion>
  
<apex:actionRegion rendered="{!IF(MONTH(TODAY()) = 1,true,false)}"> 
    <apex:pageBlock id="block9">
        <apex:pageBlockSection title="September Validation">   
              <apex:inputField value="{!Partnership_Validation__c.Choose_customer_disclosures_displayed__c}">
              <apex:actionSupport event="onchange" rerender="block9"/>
                    </apex:inputField>
              <apex:inputField value="{!Partnership_Validation__c.Specify_Other_Disclosures__c}" rendered="{!(Partnership_Validation__c.Choose_customer_disclosures_displayed__c = "Other")}"/>        
         </apex:pageBlockSection>
    </apex:pageBlock>
</apex:actionRegion>
  
<apex:actionRegion rendered="{!IF(MONTH(TODAY())= 1,true,false)}"> 
    <apex:pageBlock id="block10" >
        <apex:pageBlockSection title="October Validation">
             <apex:inputField value="{!Partnership_Validation__c.Days_per_month_you_reside_at_SRA__c}"/>
             <apex:inputField value="{!Partnership_Validation__c.Partner_provided_furniture_utilized__c}">
                 <apex:actionSupport event="onchange" rerender="block10"/>
             </apex:inputField>
             <apex:inputField value="{!Partnership_Validation__c.Type_of_space_you_occupy__c}"/>
             <apex:inputField value="{!Partnership_Validation__c.Other_Furniture__c}" rendered="{!(Partnership_Validation__c.Partner_provided_furniture_utilized__c = "Other (indicate other below)")}"/>
             <apex:inputField value="{!Partnership_Validation__c.Size_of_the_space_you_occupy_sqft__c}"/>  
         </apex:pageBlockSection>
    </apex:pageBlock> 
</apex:actionRegion>

<apex:actionRegion rendered="{!IF(MONTH(TODAY())=1,true,false)}"> 
    <apex:pageBlock id="block11">
        <apex:pageBlockSection title="November Validation">   
              <apex:inputField value="{!Partnership_Validation__c.Citi_Issued_Equiptment__c}"/>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:actionRegion>
  
<apex:actionRegion rendered="{!IF(MONTH(TODAY()) = 1,true,false)}"> 
    <apex:pageBlock id="block12">
        <apex:pageBlockSection title="December Validation">   
              <apex:inputField value="{!Partnership_Validation__c.Choose_customer_disclosures_displayed__c}">
              <apex:actionSupport event="onchange" rerender="block12"/>
                    </apex:inputField>
              <apex:inputField value="{!Partnership_Validation__c.Specify_Other_Disclosures__c}" rendered="{!(Partnership_Validation__c.Choose_customer_disclosures_displayed__c = "Other")}"/>        
         </apex:pageBlockSection>
    </apex:pageBlock>
</apex:actionRegion>

<apex:actionRegion >
     <apex:pageBlock >
          <apex:pageBlockSection title="System Information">
               <apex:inputField value="{!Partnership_Validation__c.Name}"/>
               <apex:outputField value="{!Partnership_Validation__c.CreatedDate}"/>
          </apex:pageBlockSection>
      </apex:pageBlock>  
</apex:actionRegion>  

</apex:form>
                       
</apex:page>

  

Any help at all would be extremely appreciated!!!  (and if you see something in all of that mess that I could do better in a different way, please feel free to point it out - I am trying to learn all of this from no experience at all in developing so any pointers would be helpful!)

 

Thanks!

 

bob_buzzardbob_buzzard

Does the edit page only handle edits to existing records, or is this for creating new records as well?

AmandaSilberAmandaSilber

It is also used to create new records. Thank you!

bob_buzzardbob_buzzard

The issue with creating new records is that the id isn't available from the parent controller after saving (or wasn't last time I tried).

 

I'd be inclined to carry out the insert/update in the extension controller and then I think you can just redirect to the view page.  It should be something close to:

 

public class NewPVal{
    ApexPages.StandardController controller;
    Partnership_Validation__c pval;
        public NewPVal(ApexPages.StandardController con){
                controller = con;
                pval=(Partnership_Validation__c) controller.getRecord();
                     }
                                      
public PageReference save()
 {        
         upsert pval; 
         PageReference result=Page.EmployeeValidation; // assuming this is the view page
    
         result.getParameters().put('id', pval.id);
         result.setRedirect(true);
         return result;
             }

public PageReference cancel()
{         controller.cancel();
          return null;
          }
          }

 

AmandaSilberAmandaSilber

Right, thank you for your help!! I created and tested this code last night - by no means do I think it is standard or even good (the form is probably horrid) , but it actually is working. Do you see any issues with it that may show up in the future?

 

public with sharing class NewPVal {

     Partnership_Validation__c pval;  
    ApexPages.StandardController sController;  
    
    public NewPVal(ApexPages.StandardController controller) 
    {
        sController = controller;
        pval = (Partnership_Validation__c)controller.getRecord();
    }

                                     
public PageReference savedetails() {
  sController.save();
        return page.EmployeeValidation ;
}
public PageReference cancel()
{         scontroller.cancel();
          return null;
          }
          }

 

bob_buzzardbob_buzzard

The cancel looks a bit weird to me - it will execute the parent controller cancel but then leave the user on that page.  I'm not sure what would happen if you cancelled, then added some data and then saved it.

AmandaSilberAmandaSilber

You are right, it basically just refreshes the page.  I will try your code and see if that helps - and if it works for the new/edit pages.  Thank you so much for your help! You are so nice!!  I'll let you know how it goes!

AmandaSilberAmandaSilber

So I tried out your controller and it's doing the same thing. It's not cancelling - it just refreshes the page. any ideas?

 

 

bob_buzzardbob_buzzard

There's a little confusion here - my change to the controller was to the save method, not the cancel.

 

I'd suggest that you use the default cancel from the parent controller. Try changing your cancel method to:

 

public PageReference cancel()
{         
   return scontroller.cancel();
}

 

 

 

AmandaSilberAmandaSilber

Perfect! Thank you so much for all of your help!! 

 

 

I do have one more tiny issue with my page that I haven't fixed yet - maybe you know the answer before I go searching...

 

I have the inline editing set up - with an 'Update' button that should only appear on 'edit mode' but it is there all of the time. Same with the Edit button that should only appear on the detail page.

 

Here is the vf page code:

 

 

<apex:form >
        <apex:inlineEditSupport id="inline" event="ondblclick" showOnEdit="update" hideOnEdit="edit">

<apex:pageBlock mode="maindetail"> <apex:pageBlockButtons location="top" > <apex:commandButton id="edit" value="Edit" action="{!Edit}"/> <apex:commandButton id="update" action="{!quicksave}" value="Update"/> </apex:pageBlockButtons> </apex:pageBlock>

 

bob_buzzardbob_buzzard

I've tried your code in my dev org - the edit button behaves as expected for me and disappears when I double click for inline editing.

 

In order to hide buttons in view mode and only display when editing, you need to style them as hidden:

 

 <apex:commandButton id="update" action="{!quicksave}" value="Update" style="display:none"/>

 

When you switch between inline editing and view, the button will then be toggled as expected.

AmandaSilberAmandaSilber

Perfect!! thank you sooo much for everything.  Would you mind if I saved your information for any future endeavours I may find myself upon?  I am trying to learn and self-teach the development side of salesforce - my end goal is to become a certified architect such as yourself!! (You are my new role model!)

bob_buzzardbob_buzzard

The best thing is to post here - I'm on the boards quite a bit, but there are loads of others who'll be able and willing to help also.

 

Best of luck!