2

I'm an Apex and Visualforce beginner with not much overall programming experience to boot.

I've been tasked with updating a VF page that needs to display a series of checkboxes defined in a field set. When the user clicks 'Save' on the page, the values of the selected checkboxes should be populated on a newly created record but that isn't what's happening.

I followed the Salesforce Working with Field Sets docs and was able to get the checkboxes to display on the page, but the selected values aren't being saved to the new record.

The VF page is using a standard controller for the custom object c4g_Case_Note__c with a custom controller in an extension. Here's the page def from the VF page:

<apex:page standardController="c4g_Case_Note__c" extensions="CaseNoteController" lightningStylesheets="true" sidebar="false" tabstyle="Case">

Here's the section in the page that references the field set, which is called Housing Topics:

<!--Housing Topics section-->
<apex:pageBlockSection title="Housing Topics" rendered="{!renderHousingTopics}">
    <apex:repeat value="{!$ObjectType.c4g_Case_Note__c.FieldSets.Housing_Topics}" var="f">
        <apex:inputField value="{!c4g_Case_Note__c[f]}" />
    </apex:repeat>
</apex:pageBlockSection>

I assumed that using a standard controller and an <inputField> element meant that I wouldn't need to update the controller to save the fields. I should also note that the block above is inside a set of <form> tags.

Did I so something wrong in setting up the section, or do I have to somehow track the selected fields in the controller? Thanks.

2
  • 2
    Is there a public property in the CaseNoteController extension that exposes the current record? (assume it is called theRec, then try <apex:inputField value="{!theRec[f]}" />) – cropredy Dec 19 '19 at 23:44
  • @cropredy -- That did it! The constructor creates a new object record called caseNote. I updated the value for the input field to {!caseNote[f]} and the checkbox values now save as expected. Thanks! – E. Csongradi Dec 20 '19 at 5:13
0

Per @cropredy , I needed to find a reference to the target record in the CaseNoteController constructor and update the VF page to use that reference.

I found that the constructor creates a new record:

caseNote = new c4g_Case_Note__c();

I updated the VF code to use that reference and the issue was resolved:

<!--Housing Topics section-->
<apex:pageBlockSection title="Housing Topics" rendered="{!renderHousingTopics}">
    <apex:repeat value="{!$ObjectType.c4g_Case_Note__c.FieldSets.Housing_Topics}" var="f">
        <apex:inputField value="{!caseNote[f]}" />
    </apex:repeat>
</apex:pageBlockSection>

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.