1

My question is about why is an action not executed in the controller? I noticed this behavior previously in different scenarios, but I am going to explain the issue on a particular example - when apex:inputCheckbox has a value from a Number field.

BACKGROUND

Visualforce:

<apex:page controller="testController">
    <apex:form id="testForm">
        <apex:pageBlock >
            <apex:pageBlockTable value="{! accounts }" var="acc" style="table">

                <apex:column value="{! acc.Id }"/>
                <!--
                <apex:column headerValue="Number of locations Checkbox" >
                    <apex:inputCheckbox value="{! acc.NumberofLocations__c }" ></apex:inputCheckbox>
                </apex:column>
                -->
                <apex:column headerValue="Number of locations" >
                    <apex:inputField value="{! acc.NumberofLocations__c }" ></apex:inputField>
                </apex:column>

            </apex:pageBlockTable>
            <apex:pageBlock id="hiddenBlock" rendered="false"></apex:pageBlock>
        </apex:pageBlock>

        <apex:commandButton value="Update" action="{! updateAccs }" rerender="testForm" />

    </apex:form>
</apex:page>

Controller:

public class testController
{
    public List<Account> accounts {get; set;}

    public testController()
    {
        accounts = [SELECT Id, Name, CreatedDate, NumberofLocations__c  FROM Account WHERE ID ='0011H00001QOYcs'];
    }

    public void updateAccs()
    {
        System.debug('accounts=' + accounts);
        upsert accounts;
    }
}

The debug when updateAccs() has run:

13:09:42:010 USER_DEBUG [12]|DEBUG|accounts=(Account:{Id=0011H00001QOYcsQAH, Name=Dickenson plc, CreatedDate=2018-06-13 09:15:06, NumberofLocations__c=null, CurrencyIsoCode=USD})

When I uncomment the block of code on the page and inspect the debug again:

-N/A

It's empty, because updateAccs() never gets executed. The most interesting part is that I don't see any error during compile or runtime. I made my log levels as fines as possible:

enter image description here

--UPDATE-- To avoid confusion this question is about why the action is not executed and not registered in debug logs, and not about using apex:inputCheckbox with a Number field (it's just an example).

3
  • Have you tried relating the checkbox to a boolean controller property or checkbox SObject field? Much more likely to work.
    – Keith C
    Commented Jul 20, 2018 at 10:52
  • <apex:inputCheckbox is supposed to work with a Boolean value. Can you please explain why you are mapping a number field to a Checkbox?
    – Saroj Bera
    Commented Jul 20, 2018 at 11:07
  • The question itself might has been too specific and mislead from the original issue. I have updated the post.
    – Eduard
    Commented Jul 20, 2018 at 11:34

1 Answer 1

3

The problem is that you are binding a checkbox to a number field. When calling the action the system tries to assign the Boolean to the number field. Try adding <apex:pageMessages id="messages" /> to your page, and add messages you the rerender attribute of your button. You will see an error message relating to assigning a Boolean to a number field.

What it essentially boils down to is that you're getting a validation error when you're posting your form, but there's no displaying of error messages. Hence, you do not see that anything is going wrong. Adding the pageMessages element and rerendering that fixes this issue. If, for instance, your action now has an unhandeld exception that will also show up in that message box.

1
  • Thank's for your answer. Indeed adding pageMessages element to the page allowed to see the actual error.
    – Eduard
    Commented Jul 20, 2018 at 12:27

You must log in to answer this question.

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