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
aKallNVaKallNV 

VF controller: Why aren't two of several fields being saved?

The code posted below is a small portion of a VF controller. This portion is part of a Save Method that inserts a new record in a custom object. I have had this working fine for a few weeks now. However, I was just provided a new business need, which is simply the addition of two new fields. For some reason the data in these fields are not being inserted. All of the other fields are being saved just fine. The two new fields are callled CategoryofWork__c and HoursSpent__c. They are simply a picklist field and an integer field. I can't spot any difference between them and the other fields that would prevent them from being inserted. No errors are thrown. The record simply saves without the data.

 

Any ideas?

 

Thanks!

 

 //Method called by Save Button
        public PageReference processSelected() {  
            
            //insert new Log
            SchoolWorkPlanLog__c newLog = new SchoolWorkPlanLog__c(
                Account__c = accountID,
                Subject__c = this.getLog.Subject__c,
                Narrative__c = this.getLog.Narrative__c,
                InteractionDate__c = this.getLog.InteractionDate__c, CategoryofWork__c = this.getLog.CategoryofWork__c,                
                HoursSpent__c = this.getLog.HoursSpent__c,
                Category__c = this.getLog.Category__c,
                OffPlan__c = this.getLog.OffPlan__c,
                Department__c = this.getLog.Department__c,
                Unit__c = this.getLog.Unit__c
            );
            
                      
                insert newLog;

 

bob_buzzardbob_buzzard

Is FLS set up correctly for these fields?  Other than that, its a bit difficult without seeing the page and how the fields are bound in.

aKallNVaKallNV

I have just established that it has something to do with my vf page. The markup below is the version that doesn't work....the new fields don't save. It has something to do with the fact that I have them housed in output panels that are being renderedn by the {!selectedRT} field. I noticed some strange behavior once I put the fields inside of outputPanels. The first was that names of the fields were not pulled in automaticallys as you would expect them to be since they are fields defined for the sObject. So, I had to create outputLabels for them in order to display the field name. 

 

I found that if I strip away the ajax stuff and just display them like the other fields the data is saved as expected. Not sure where to go from here. Thinking about putting the two fields into their own pageBlockSection, but posting now incase there is somehthing fundamental that I am doing wrong.

 

Thanks!

<apex:pageBlockSection title="{!swpnAccount}" columns="1">
              <apex:inputField value="{!getLog.Subject__c}"/>
              <apex:inputField value="{!getLog.InteractionDate__c}"/>
                  <apex:actionRegion >
                  <b><apex:outputLabel value="Do You Need To Log Hours For a Coach Case?" for="rtControl"/></b>                 
                  <apex:selectList value="{!selectedRT}" size="1" id="rtControl">
                      <apex:selectOptions value="{!RTControl}"/>
                      <apex:actionSupport event="onchange" reRender="hoursSpent, workCaty, tab3" action="{!makesCaseWrappers}"/>
                  </apex:selectList>
                  </apex:actionRegion>  
              <apex:outputPanel id="hoursSpent">
                  <b><apex:outputLabel value="Hours Spent" rendered="{!showCoachFields}"/></b>
                  <apex:inputField value="{!getLog.HoursSpent__c}" rendered="{!showCoachFields}" />
              </apex:outputPanel>
              <apex:outputPanel id="workCaty">
                  <b><apex:outputLabel value="Category of Work" rendered="{!showCoachFields}"/></b>
                  <apex:inputField value="{!getLog.CategoryofWork__c}"  rendered="{!showCoachFields}"/>
              </apex:outputPanel>
              <apex:inputField value="{!getLog.Narrative__c}" style="width:90%"/>
      </apex:pageBlockSection>

 

 

 

aKallNVaKallNV

I have revised the markup, which now looks much better because it doesn't require me to have outputLable tags for the two fields. However, the two fields are still not saving. 

 

So In this version the Category of Work and Hours Spent field are not being inserted.

 

<apex:pageBlockSection title="{!swpnAccount}" columns="1">
              <apex:inputField value="{!getLog.Subject__c}"/>
              <apex:inputField value="{!getLog.InteractionDate__c}"/>
                  <apex:actionRegion >
                  <b><apex:outputLabel value="Do You Need To Log Hours For a Coach Case?" for="rtControl"/></b>                 
                  <apex:selectList value="{!selectedRT}" size="1" id="rtControl">
                      <apex:selectOptions value="{!RTControl}"/>
                      <apex:actionSupport event="onchange" reRender="coachCorner, tab3" action="{!makesCaseWrappers}"/>
                  </apex:selectList>
                  </apex:actionRegion>
      <apex:pageBlockSection id="coachCorner" >
                  <apex:inputField value="{!getLog.HoursSpent__c}" rendered="{!showCoachFields}" />
                  <apex:inputField value="{!getLog.CategoryofWork__c}"  rendered="{!showCoachFields}"/>
      </apex:pageBlockSection>        
              <apex:inputField value="{!getLog.Narrative__c}" style="width:90%"/>
      </apex:pageBlockSection>

  However, in this version they are:

<apex:pageBlock mode="edit" id="pb1">  
      <apex:pageBlockSection title="{!swpnAccount}" columns="1">
              <apex:inputField value="{!getLog.Subject__c}"/>
              <apex:inputField value="{!getLog.InteractionDate__c}"/>
              <!--<apex:inputField value="{!getLog.PreEngagementPlan__c}"/>-->
                  <!--<apex:actionRegion >
                  <b><apex:outputLabel value="Do You Need To Log Hours For a Coach Case?" for="rtControl"/></b>                 
                  <apex:selectList value="{!selectedRT}" size="1" id="rtControl">
                      <apex:selectOptions value="{!RTControl}"/>
                      apex:actionSupport event="onchange" reRender="coachCorner, tab3" action="{!makesCaseWrappers}"/>
                  </apex:selectList>
                  </apex:actionRegion>-->
      <apex:pageBlockSection id="coachCorner" >
                  <apex:inputField value="{!getLog.HoursSpent__c}"  />
                  <apex:inputField value="{!getLog.CategoryofWork__c}"  />
      </apex:pageBlockSection>        
              <apex:inputField value="{!getLog.Narrative__c}" style="width:90%"/>
      </apex:pageBlockSection>

 

aKallNVaKallNV

If anybody is still reading this. I have debugged a little further but still lost.

 

I have now figured out that it has something to do with the mehtod that I use to control the appearance of the field. So when the the tags for the two fields include rendered = {!showCoachFields} the values are not saved. 

 

So now I am going to post the VF again, and the method that is causing the problem.

 

<apex:pageBlockSection title="{!swpnAccount}" columns="1">
              <apex:inputField value="{!getLog.Subject__c}"/>
              <apex:inputField value="{!getLog.InteractionDate__c}"/>
              <!--<apex:inputField value="{!getLog.PreEngagementPlan__c}"/>-->
                  <apex:actionRegion >
                  <b><apex:outputLabel value="Do You Need To Log Hours For a Coach Case?" for="rtControl"/></b>                 
                  <apex:selectList value="{!selectedRT}" size="1" id="rtControl">
                      <apex:selectOptions value="{!RTControl}"/>
                      <apex:actionSupport event="onchange" reRender="coachCorner, tab3" action="{!makesCaseWrappers}"/>
                  </apex:selectList>
                  </apex:actionRegion>
     <apex:pageBlockSection id="coachCorner" >
                  <apex:inputField value="{!getLog.HoursSpent__c}"   rendered="{!showCoachFields}" />
                  <apex:inputField value="{!getLog.CategoryofWork__c}"  rendered="{!showCoachFields}" />
      </apex:pageBlockSection>
              <apex:inputField value="{!getLog.Narrative__c}" style="width:90%"/>
      </apex:pageBlockSection>

 

 

public Boolean showCoachFields {
                get{if(this.selectedRT == 'Yes'){return true;} else{return false;}
                }       
        }

 

bob_buzzardbob_buzzard

But presumably the fields are rendered on the page, and you can make selections etc?

bob_buzzardbob_buzzard

One thing occurs to me - are the fields not being saved when you change the value for the selectlist?  Or are you saving through buttons elsewhere? 

 

You are using an actionregion, so when the selectlist is updated only the fields enclosed in the actionregion are sent back to the server.

aKallNVaKallNV

To answer both posts:

 

first post: Yes the fields are being rendered on the page as I intend...which is for the user to answer the prompt 'Do you need to Log Hours...' This value is defaulted to 'No' in the contructor. If they chose yes then the showCoachFields method is kicked into gear and two fields appear on the page. 

 

second post: I am saving with a separate Save button and method. I have confirmed that it is not the change in value of the selectList. To confirm this I did the following: I removed the rendered = {!showCoachFields} from the two fields making them both automatically visible, but I left the controlling selectList as is so that it would still reRender them. I then found that the data in both fields is saved even after changing the selected option.

bob_buzzardbob_buzzard

Have you tried wrapping the fields inside an outputpanel and re-rendering that based on the value of showCoachFields? 

aKallNVaKallNV

Tried that too. 

 

I figured out a much easier to solution to this problem. I should have posted this yesterday when I figured this out...it makes feel a little ridiculous. I simply made a second profile. One profile can view/edit the two fields and the other profile can't. However, I think it's still strange the way the page was behaving.

 

 

bob_buzzardbob_buzzard

I'd agree re: the strangeness.  How you render then shouldn't matter, but it seems to!