You need to sign in to do that
Don't have an account?
IoniaCorp
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.
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.
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: ) :
All Answers
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)
Thanks
If you're doing all of that, you should be set.
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!!
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: ) :