Because you are checking the values of the variable record
that you have just declared.
If you try to replace
Intake__c record = new Intake__c();
with (could be wrong depending on the scenario, continue reading)
Intake__c record = (Intake__c)Intake.getRecord();
You would have an issue as the standard controller only brings with it the fields that are requested on the page (besides the Id)
You have (at least) two options:
- You could add hidden fields to your view that includes the fields you would use in your extension(s), which adds "coupling", which is NOT recommended.
- Y could take the id and query the fields you need yourself.
Following number 2, you would need to replace it with
Id recordId = ((Intake__c)Intake.getRecord()).Id;
if (recordId == null) {
return true; // or false, whatever you want
} else {
Intake__c record = [
SELECT
Personal_Care__c,
Physical_Concerns__c
FROM Intake__c
WHERE Id = :recordId
];
// the rest of the method
}// close them properly ;)
Result after chat
For future reference, in case it helps (a possible solution). also possible to have an apex:function called on the onChange of each apex:inputField, for example
Page
<apex:page standardController="Intake__c" extensions="IntakeExtension,ShouldShowSHSection" standardStyleSheets="false" showHeader="false" sidebar="false">
<apex:form>
...
<apex:pageBlock>
<apex:pageBlockSection >
<apex:inputField styleClass="fieldset" value="{!Intake__c.Personal_Care__c}">
<apex:actionSupport event="onchange" reRender="technologyRecommendation"/>
</apex:inputField>
</apex:pageBlockSection>
<apex:pageBlockSection >
<apex:inputField styleClass="fieldset" value="{!Intake__c.Physical_Concerns__c}">
<apex:actionSupport event="onchange" reRender="technologyRecommendation"/>
</apex:inputField>
</apex:pageBlockSection>
</apex:pageblock>
...
<apex:pageBlock id="technologyRecommendation">
<apex:pageBlockSection rendered="{!shouldShowSHSection}">
<apex:outputText value="SH System Recommendation"/>
</apex:pageBlockSection>
</apex:pageBlock>
....
</apex:form>
</apex:page>
Apex
public with sharing class ShouldShowSHSection {
Intake__c record;
public ShouldShowSHSection(ApexPages.StandardController paramController) {
record = (Intake__c)paramController.getRecord();Intake = paramController;
}
public Boolean getShouldShowSHSection() {
return record.Personal_Care__c != null && record.Personal_Care__c.contains('Bathroom') && record.Physical_Concerns__c == null;
}
}