0

I am trying to update the checkbox(checked or unchecked) in the database from the UI. I am calling the js function on onclick of checkbox and invoking controllers action but I am getting this error.

public class CheckboxFunctionality 
{
    public List<Account> accList{get;set;}
    public String recordId{get;set;}
    public CheckboxFunctionality()
    {
        accList = new List<Account>();
        accList = [Select id, name, phone, isActive__c  From Account Order By LastModifiedDate Limit 5];
    }

    public PageReference checkActive()
    {
        system.debug('------------'+recordId);
        Account acc = new Account();
        acc.id = recordId;
        if(acc.isActive__c == true)
            acc.isActive__c = false;
        else 
            acc.isActive__c = true;
        update acc;
        return null;
    }
}

    <apex:page controller="CheckboxFunctionality">
    <apex:form>
        <apex:actionFunction name="callAF" action="{!checkActive}" reRender="pbt">
            <apex:param id="accId" value="" assignTo="{!recordId}"/>
        </apex:actionFunction>
        <apex:pageBlock>
            <apex:pageBlockTable value="{!accList}" var="row" id="pbt">
                <apex:column>
                <apex:inputField value="{!row.isActive__c}" onclick="check('{!row.Id}')"/>
            </apex:column>
                <apex:column value="{!row.name}"/>
                <apex:column value="{!row.Phone}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
    <script>
        function check(recId)
        {
            alert('---'+recId);
            callAF(recId);
            alert('122345');
        }
    </script>
</apex:page>

Also

Uncaught SyntaxError: Unexpected token :

this is coming in console.

1 Answer 1

2

Give your apex:param name attribute. So it will work.

<apex:actionFunction name="callAF" action="{!checkActive}" reRender="pbt"> <apex:param name="apparam" id="accId" value="" assignTo="{!recordId}"/> </apex:actionFunction>

This will not give you compile time error but name is the required attribute of apex:param tag

3
  • thanks for the reply its working now. But now in my controller only else condition is working I dint know why its happening
    – Anzar
    Oct 23, 2016 at 5:12
  • @Anzar because you create a new instance of Account and acc.isActive__c you never set thi so this will always be false. Also if this works for you then you can accept this answer. Oct 23, 2016 at 5:31
  • sure, I got it how I could I rectify it
    – Anzar
    Oct 23, 2016 at 5:37

You must log in to answer this question.

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