+ Start a Discussion

How to update Records using input checkbox field in custom visualforce page??



Based on the selected values through the checkbox field i need to update my records

I had tried with the UI checkboxes and its works fine in my visualforce page,

But instead of using UI checkbox now i need to use one of the checkbox field to do the same task (One of the field in my object)



Is there any solution to do that??

Your suggestions are most wellcome...

Best Answer chosen by Admin (Salesforce Developers) 

The only two changes to your code would be to 1) link the checkbox to the custom field, and 2) use the controller's logic to test the checkbox's state and take the appropriate action.


<apex:page controller="theController">
    <apex:inputField value="{!rec.check__c}"/>
    <apex:inputField value="{!rec.field__c}"/>
    <apex:commandButton action="{!update}" value="Go!"/>


public class theController {
  public record__c rec { get; set; }
  public thecontroller() {
    rec = new record__c();
  public void update() {
      rec.field__c = 'hello world';
      rec.field__c = 'goodbye world';

This horribly simple example illustrates the mechanism that you might use to cause an update to one field based on another field. This is not the only possible method of doing this, either. You could use an AJAX event, or perform actions as part of a save action.


Then again, if you want consistency (such as with the API and standard pages), you might instead opt to use a Workflow Rule Field Update or Apex Trigger to accomplish the same effect consistently across all available means of creating or editing a record.