0

I have a field that is rendered like so:

      <apex:pageBlockSectionItem >
          <apex:outputLabel value="{!$ObjectType.Event.fields.Customer_Facing_Event__c.Label}" for="{!event.Customer_Facing_Event__c}" />
           <apex:actionRegion immediate="true">
              <apex:inputField value="{!event.Customer_Facing_Event__c}">  
                 <apex:actionSupport event="onchange"  reRender="pbs_customerToMeet"/>
              </apex:inputField>
          </apex:actionRegion>
      </apex:pageBlockSectionItem>

This is a boolean field that defaults to true. I'd like to use the value of this field to toggle the visibility of a Page Block Section, like so:

 <apex:pageBlockSection title="CUSTOMER TO MEET" collapsible="false" id="pbs_customerToMeet" 
         rendered="{!event.Customer_Facing_Event__c}">  
      {!event.Customer_Facing_Event__c} 
      <apex:pageBlockSectionItem >
 </apex:pageBlockSection>

The problem is that, although the field defaults to true, it appears that the value of the field is in fact false, and Salesforce instead just renders the input as checked. This causes my PageBlockSection to not be visible on the initial page render.

How can I make the section render initially?

3
  • one thing to be aware of is that the immediate="true" will cause no data from your form to be posted back to the controller, including the value of the checkbox event.Customer_Facing_Event__c. If you remove this attribute does the behavior change?
    – Mark Pond
    Commented Mar 23, 2016 at 23:12
  • are you saying that a) the pageblockSectionItem inputField renders as checked but the pageBlockSection does not render on page load? and b) is there a controller extension involved and how does it instantiate the getter for event?
    – cropredy
    Commented Mar 23, 2016 at 23:41
  • a) yes, that is my problem. b) there is a controller extension for this page, the event property on the controller is populated as so: (Event)controller.getRecord(); Commented Mar 25, 2016 at 17:17

1 Answer 1

0

You have to submit pbs_customerToMeet parent element in your reRender call

5
  • 1
    Could you clarify what you mean by this? Commented Mar 23, 2016 at 22:28
  • pbs_customerToMeet is pageBlockSection, and in you case it is not rendered initially, so when you have reRender="pbs_customerToMeet" it's not going to be rerender. I suggested to modify reRender from actionSupport to use pbs_customerToMeet's parent element which in your case would be pageBlock. It has to be like reRender="YourPageBlockName"
    – o-lexi
    Commented Mar 23, 2016 at 23:15
  • Ah ok, got it now. But the problem is not what happens when actionSupport executes, the problem is the fact that the value of the field is false even though it is configured to default to true. It would appear that when a Boolean field is configured to default to true, salesforce simply renders the checkbox as ticked as opposed to setting the value of the field to true. Commented Mar 23, 2016 at 23:25
  • It looks like defaults are set on a Database level. Here is workaround: salesforce.stackexchange.com/a/75383/12440
    – o-lexi
    Commented Mar 23, 2016 at 23:52
  • It would look like that workaround would indeed work for me, but the Event object does not appear to have a property called sObjectType on it. This means that the line: this.event = Event.sObjectType.newSObject(null, true); fails to compile with the error Invalid field sobjecttype for SObject Event Commented Mar 25, 2016 at 17:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .