function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
VinuVinu 

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

Hi

 

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) 
sfdcfoxsfdcfox

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:form>
    <apex:inputField value="{!rec.check__c}"/>
    <apex:inputField value="{!rec.field__c}"/>
    <apex:commandButton action="{!update}" value="Go!"/>
  </apex:form>
</apex:page>

 

public class theController {
  public record__c rec { get; set; }
  public thecontroller() {
    rec = new record__c();
  }
  public void update() {
    if(rec.check__c)
      rec.field__c = 'hello world';
    else
      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.