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
BalkishanBalkishan 

How to edit records by selecting checkboxes?

Hi,

I have been given an assignment. Which is as per follow:-

Create a VF page 
This page contains list of contacts.
By default these records are not editable.
Each record has a checkbox.
If user clicks on a checkbox, then corresponding record will become editable.
User can modify that reocrd
Like that user can select multiple records and can modify them.
After changes, save all only those records which are editable.
After saving the records refresh page and display updated record.
All checkboxes now should become unchecked.

I have create a VFpage and a controller for that but i unable to get desire output.Vf page code is as shown
<apex:page controller="BulkUpdateController">
<apex:form >
   <apex:actionFunction name="selectCheckBox" action="{!selectCheckBox}" rendered="block">
   <apex:param name="a" value="" assignTo="{!selectedCheckBox}"/>
   </apex:actionFunction>
    <apex:pageBlock >
     <table>
        <tr>
            <th>First Name</th>
            <th>Last Name</th>
            <th>Email</th>
        </tr>
        <tr>
        <apex:repeat value="{!RecordList}" var="rec">
        <tr>
            <td><apex:inputText value="{!rec.FirstName__c}" disabled="true"/></td>
            <td><apex:inputText value="{!rec.LastName__c}" disabled="true"/></td>
            <td><apex:inputText value="{!rec.Email__c}" disabled="true"/></td>
            <td><apex:inputCheckbox value="{!rec.CheckIn__c}" onclick="select()"/></td>
        </tr>   
        </apex:repeat>
        </tr>
     </table>
        <apex:pageBlockButtons >
          <apex:commandButton value="Save" action="{!SaveMe}"/>
          <apex:commandButton value="Cancel" action="{!Cancel}"/>     
        </apex:pageBlockButtons>     
    </apex:pageBlock>
    <script>
       function select(){
         alert('hello');
         selectCheckBox(RecordList.value);
        }
    </script>
</apex:form>
</apex:page>

code for controller is

public class BulkUpdateController{
    public List<Student__c> RecordList{get;set;}
    public Boolean selectedCheckBox{get;set;}
       public BulkUpdateController(){
       RecordList = new List<Student__c>();
      
       RecordList = [SELECT FirstName__c, LastName__c, Email__c, checkIn__c FROM student__c];
    }
      public PageReference SaveMe(){
        upsert RecordList;
        // PageReference pg = new PageReference('/' + student.id);
        return null;
    }
   
     public PageReference Cancel(){
     pagereference pg = new pagereference('https://ap1.salesforce.com/home/home.jsp');
    return pg;
    }
    public PageReference selectCheckBox(){
    RecordList = new List<Student__c>();
    RecordList = [SELECT FirstName__c, LastName__c, Email__c, checkIn__c FROM student__c WHERE checkIn__c =: selectedCheckBox];
    return null;
    }
}
This is the code for page and controller.Am i coding in right way.please Help me if somebody can.