0

I have a check box for the Account object given below in my vf page

<apex:outputLabel ><apex:inputField value="{!acctObj.Decline_Credit_Check__c}"/>&nbsp;&nbsp;Decline Credit Check </apex:outputLabel>

I am fairly new to salesforce and want to know how can I save and update the value of checkbox everytime it is checked or unchecked .

2

You can use a commandLink to save the change. That said, I'd recommend using a wrapper class to make your life easier:

public class AccountWrapper {
    public class Account { get; set; }
    public void updateRecord() {
        update account;
    }
    public AccountWrapper(Account record) {
        account = record;
    }
}

Using a wrapper, you'd want to modify your Visualforce:

<apex:inputField value="{!acctObj.account.Decline_Credit_Check__c}"/>
    <apex:commandLink action="{!acctObj.updateRecord}" value="Decline Credit Check" />

Obviously, you'll need to modify how acctObj is being set, because it'll be a wrapper now. That'll generally look like:

AccountWrapper[] items = new AccountWrapper[0];
for(Account record: recordsFromQuery) {
    items.add(new AccountWrapper(record));
}
return items;

Alternatively, you could use an actionSupport with an onclick handler:

<apex:inputField value="{!acctObj.account.Decline_Credit_Check__c}">
    <apex:actionSupport event="onclick" action="{!acctObj.updateRecord}" reRender="form" />
</apex:inputField>

There is, of course, other ways to do this, but these are probably some of the most common ways of doing so.

|improve this answer|||||

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.