I am trying to create an Apex page attached to a List Button that will take the selected records and flip the boolean value of a particular column. I have the page basically working the way I want it to in that it shows the selected records, shows the old boolean values as a outputField, and allows edits on the same field as an bound inputCheckbox (and saves and cancels appropriately. What I am having an issue with however, is in the InputCheckbox, I'd like it to default to the opposite boolean value of the current value. This way, the user would only have to confirm the "flips" by clicking Save. I am trying to use !IF, but I get and Syntax error, missing')'. Here is my code:

<apex:page standardController="Contact" recordSetVar="Contacts">
    <apex:pageBlock title="Toggle Inactive Status">
    <apex:pageBlockButtons >
    <apex:commandButton value="Save" action="{!save}"/>
     <apex:commandButton value="Cancel" action="{!cancel}"/>
    <apex:pageBlockTable value="{!selected}" var="selectedcontact">
    <apex:column headerValue="Contact">
    <apex:outputField value="{!selectedcontact.Name}" />
    <apex:column headerValue="Old Inactive Value">
    <apex:outputField value="{!selectedcontact.Inactive__c}" />
    <apex:column headerValue="New Inactive Value">
    <apex:inputCheckbox selected="{!IF(selectedcontact.Inactive__c=true,false,true)}" value="{!selectedcontact.Inactive__c}"/>

By stripping the code down to bare minimum, I discovered that it seems Visualforce resolved the Boolean value as an Object, causing this error. After several alternatives, I came up with a working solution:


This will check the box when Inactive is false, and uncheck it when it is true. Boolean values are typically already Boolean values, and do not normally require an IF statement. That aside, you may want to consider logging a case for this issue, as the original code should have worked, as far as I can tell.

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.