+ Start a Discussion
IoniaCorpIoniaCorp 

Visualforce page in updatable mode

I have the following requirement -

I have an object(Student) that has two fields: one CheckBox type and other Text type (scenario - Pass/Fail status and Student Name).
What I am trying to do is get the student object information in the visualforce page in updatable mode. Check/Uncheck one or more student record(s) and carry out the required operation with the help of a custom button(e.g. select students named name1, name3,name5 and change their Pass/Fail status to Pass by clicking the button Change status to Pass) at once.

Any suggestions will be appreciated.

Thanks in advance.
Best Answer chosen by Admin (Salesforce Developers) 
jlojlo

Your declaration of a 'student' variable in two different scopes was confusing things a bit. At the point where your code calls 'update student', the 'Student__c student' class variable had never been initialized, which is what was causing your null pointer error. Try this (or the code-free View described above :smileyhappy: ) :

Code:
public class StudentController 
{
    List<Student__c> students;
            
    public StudentController() {}

    public List<Student__c> getStudents() {
     if(students == null){
          students = [select Pass_Fail_Status__c,Student_Name__c from Student__c where Pass_Fail_Status__c=FALSE];
     }     
          
        return students;
    }
                         
    public PageReference save() {        
       update students;           
       PageReference navigatePage = new PageReference('/apex/'+'Students_Test');
       navigatePage.setRedirect(true);
       return navigatePage;
    } 
}

 

All Answers

jlojlo
You can accomplish this functionality without Visualforce.

You will want to navigate to Setup > App Setup > Customize > User Interface. Once there, you'll want to "Enable Inline Editing" and "Enable Enhanced Lists". Then all you need to do is create the appropriate Student "View".

This SFDC "help" link might be useful:

Using Inline Editing in Lists  (you may need to modify the instance name, but the url is:  https://na3.salesforce.com/help/doc/en/inline_editing_in_a_list.htm#topic-title)




IoniaCorpIoniaCorp
Jlo thanks for the response. I have tried that option already. The problem with this is when we make some changes on (checks/unckecks) and hit Refresh it doesn't display the changes. I want to create a custom button so that I have a set of only unchecked list first(failed students only), i check some of them(change status to pass), and then when i click the custom buttom (Change status to Pass) I want to see the remaining failed students only.

Thanks
jlojlo
The problem that you might be running in to might just be that you need to click on the highlighted "Refresh" link.
 
I'm making the following assumptions about your config:
  • Your Pass/Fail status field is called "Passed?"
  • By default the "Passed?" field is unchecked
  • Your filter is: "Passed? equals False".
I'm also assuming that your work process looks like this:
  • Select a number of Student records
  • Double-click on one of the "Passed?" fields
  • Apply the changes to "All selected records"
  • Click "Save"
  • Click on the highlighted "Refresh" link at the top of the view.

If you're doing all of that, you should be set.

IoniaCorpIoniaCorp
By using visualforce I am creating a custom page where I am able to display the Pass/Fail status & Name in gridview format using the <pageblockTable> tag. I have the Pass/Fail status field in edit mode where I am able to change the pass/fail status to pass by checking the checkbox. I have the change status to pass button which has a attached logic to update the student object and refresh the page with the list of failed students only.

the sample logic is as follows:

---------------------------------------------------------------------------------------------
 public class StudentController
    {

       Student__c student;
           
     public StudentController() {
           
      }

     public List<Student__c> getStudent() {
    
         List<Student__c>  student = new List<Student__c>();
         student= [select Pass_Fail_Status__c,Student_Name__c from Student__c where Pass_Fail_Status__c=FALSE];     
         return student;
      }
                        
  public PageReference save() {       
      update student;          
      PageReference navigatePage = new PageReference('/apex/'+'Students_Test');
      navigatePage.setRedirect(true);
      return navigatePage;
   }
      
}
---------------------------------------------------------------------------------------------
the sample visual force page is as follows:
******************************************************************************
<apex:page standardStylesheets="false" controller="StudentController" id="thePage" >
    <apex:pageBlock title="Hello {!$User.FirstName}!">               
    </apex:pageBlock>
   <apex:form >
        <apex:pageBlock mode="edit">
        <apex:pageBlockSection title="Failed students information.">         
        <apex:pageblockTable value="{!student}" var="stnt">
        <apex:column ><apex:inputField value="{!stnt.Pass_Fail_Status__c}" /></apex:column>
       <!-- <apex:column value="{!stnt.Pass_Fail_Status__c}" /> -->   
            <apex:column value="{!stnt.Student_Name__c}"/>               
        </apex:pageblockTable>
       
        </apex:pageBlockSection>
     <apex:pageBlockButtons >
          <apex:commandButton action="{!save}" value="Change Status to Pass"/>
        </apex:pageBlockButtons>       
         </apex:pageBlock>
          
 </apex:form >   
</apex:page>
******************************************************************************
After the clicking event on Change Status to Pass I am getting the following exception:

System.NullPointerException: Attempt to de-reference a null object

Class.StudentController.save: line 18, column 14
External entry point

The line 18 is the update student

Trying to figure out this exception!!


jlojlo

Your declaration of a 'student' variable in two different scopes was confusing things a bit. At the point where your code calls 'update student', the 'Student__c student' class variable had never been initialized, which is what was causing your null pointer error. Try this (or the code-free View described above :smileyhappy: ) :

Code:
public class StudentController 
{
    List<Student__c> students;
            
    public StudentController() {}

    public List<Student__c> getStudents() {
     if(students == null){
          students = [select Pass_Fail_Status__c,Student_Name__c from Student__c where Pass_Fail_Status__c=FALSE];
     }     
          
        return students;
    }
                         
    public PageReference save() {        
       update students;           
       PageReference navigatePage = new PageReference('/apex/'+'Students_Test');
       navigatePage.setRedirect(true);
       return navigatePage;
    } 
}

 

This was selected as the best answer
IoniaCorpIoniaCorp
Thanks jlo for your suggestions, finally am able to solve this problem, using visualforce.