You need to sign in to do that
Don't have an account?
Isaac Gomolka
Help with Visualforce Extension Class
Hi everyone, so I'm having trouble making my extension class for my VF page be able to interact with custom fields that I need. When the picklists in my VF page get selected Yes/No it triggers a method in the extension class to check a checkbox Checked for Yes, Not Checked for No. But as of right now when I run my VF page and try to select Yes/No it gives me the error "Attempt to de-reference a null object. Error is in expression '{!setDataIntegrity}' in page escalation_question_page: Class.EscalationPageExtension.setDataIntegrity: line 31, column 1". So there is clearly something wrong when trying to check the checkbox.
Any help would be absolueltly fantastic and greatly appreciated. If you would also be able to give me an exmaple of how my Test Class for the extension would look I would really appreciate it. Im horrible with test classes and have no idea how it would look. Thanks again!
Extension:
VF Page
Thanks again in advanced for the help!
Any help would be absolueltly fantastic and greatly appreciated. If you would also be able to give me an exmaple of how my Test Class for the extension would look I would really appreciate it. Im horrible with test classes and have no idea how it would look. Thanks again!
Extension:
/*************************************************************** * Used for the Visualforce page Escalation Question Page * Created by Isaac Gomolka * 7/13/2017 * ************************************************************/ public with sharing class EscalationPageExtension { public String picklist1{get;set;} public String picklist2{get;set;} public String picklist3{get;set;} private Case cases; private ApexPages.StandardController ctrl; public EscalationPageExtension(ApexPages.StandardController controller) { ctrl = controller; this.ctrl = ctrl; } public List<SelectOption> options { get; private set; } { options = new List<SelectOption>(); options.add(new SelectOption('', '-Select-')); // ==> option null options.add(new SelectOption('false', 'No')); options.add(new SelectOption('true', 'Yes')); } public void setDataIntegrity() { this.cases.Escalation_Data_Integrity__c = Boolean.valueof(picklist1); } public void setViableWorkaround() { this.cases.Escalation_Viable_Workaround__c = Boolean.valueof(picklist2); } public void setAppFunction() { this.cases.Escalation_Application_Functionality__c = Boolean.valueof(picklist3); } }
VF Page
<apex:page standardController="Case" extensions="EscalationPageExtension"><!-- We should keep sidebars and headers to give them a way out --> <apex:pageBlock title="{!$User.FirstName}, Answer Questions to Escalate Case."> <apex:form id="formID"> <h1>How many users are affected?</h1> <apex:inputField value="{! Case.Escalation_Users_Affected__c }" required="true"/> <br/> <h1>Does this affect data integrity?</h1> <apex:actionRegion > <apex:outputPanel styleClass="requiredInput" layout="block"> <apex:outputPanel styleClass="requiredBlock" layout="block"/> <apex:selectList value="{!picklist1}" size="1" required="true"> <apex:actionSupport event="onchange" rerender="hidepanel1" action="{!setDataIntegrity}"/> <apex:selectOptions value="{!options}" /> </apex:selectList> </apex:outputPanel> </apex:actionRegion> <br/> <apex:outputPanel id="hidepanel1"> <apex:outputText value="How?" style="display:{!if(picklist1=='true', 'block', 'none')}"/> <apex:inputField value="{!Case.Escalation_Data_Integrity_Explain__c}" required="{!picklist1}" style="display:{!if(picklist1=='true', 'block; width:250px; height:75px;', 'none')}"/> <!-- <apex:inputCheckbox value="{!Case.Escalation_Data_Integrity__c}" selected="true" style="display:none;" rendered="{!picklist1}"/> --> </apex:outputPanel> <br/> <br/> <h1>Do you have a viable workaround?</h1> <apex:actionRegion > <apex:outputPanel styleClass="requiredInput" layout="block"> <apex:outputPanel styleClass="requiredBlock" layout="block"/> <apex:selectList value="{!picklist2}" size="1" required="true"> <apex:actionSupport event="onchange" rerender="hidepanel2" action="{!setViableWorkaround}"/> <apex:selectOptions value="{!options}" /> </apex:selectList> </apex:outputPanel> </apex:actionRegion> <br/> <apex:outputPanel id="hidepanel2"> <apex:outputText value="What is the viable workround?" style="display:{!if(picklist2=='true', 'block','none')}"/> <apex:inputField value="{!Case.Escalation_Viable_Workaround_Explain__c}" required="{!picklist2}" style="display:{!if(picklist2=='true', 'block; width:250px; height:75px;', 'none')}" /> <!-- <apex:inputCheckbox value="{!Case.Escalation_Viable_Workaround__c}" selected="true" style="display:none;" rendered="{!picklist2}"/> --> </apex:outputPanel> <br/> <br/> <h1>Does this affect critical application functionality?</h1> <apex:actionRegion > <apex:outputPanel styleClass="requiredInput" layout="block"> <apex:outputPanel styleClass="requiredBlock" layout="block"/> <apex:selectList value="{!picklist3}" size="1" required="true"> <apex:actionSupport event="onchange" rerender="hidepanel3" action="{!setAppFunction}"/> <apex:selectOptions value="{!options}" /> </apex:selectList> </apex:outputPanel> </apex:actionRegion> <br/> <apex:outputPanel id="hidepanel3"> <apex:outputText value="How?" style="display:{!if(picklist3=='true', 'block','none')}"/> <apex:inputField value="{!Case.Escalation_App_Functionality_Explain__c}" required="{!picklist3}" style="display:{!if(picklist3=='true', 'block; width:250px; height:75px;', 'none')}" /> <!-- <apex:inputCheckbox value="{!Case.Escalation_Application_Functionality__c}" selected="true" style="display:none;" rendered="{!picklist3}"/> --> </apex:outputPanel> <br/> <br/> <h1>What business functionality are you unable to perform?</h1> <br/> <apex:inputField value="{! Case.Escalation_Business_Functionality__c }" style="width: 300px; height: 100px" required="true"/> <br/> <br/> <br/> <apex:inputCheckbox value="{!Case.IsEscalated}" selected="true" style="display:none;"/> <apex:commandButton action="{!save}" value="Submit" /> </apex:form> </apex:pageBlock> </apex:page>
Thanks again in advanced for the help!
1) prepare necessary test data with all necessary fields for your case object that you are going to test
2) try to test the extension controller as mentioned below examples (https://developer.salesforce.com/forums/?id=906F00000008y7QIAQ)
test method
3) for figuring out select option test please go through this link (https://developer.salesforce.com/forums/?id=906F00000008zA1IAI)
This would be my best approach to start, if you need any further assistance please go through this link (https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_error_handling.htm)
Let me know, what you tried for writing the test classs and post it here so that i can assist you better
Thank you!
All Answers
If this helps to solve your problem, please choose this as best answer.
Thank you!
Thanks!
Visual force page
Controller
So to test this page pass the account id parameter in the url of the visual force page and select an option, opent the account and observe the description field.
I feel you need to figure out some thing similar to this as per your requirement.
If this helps to reach your approach please choose this as the best answer.
Thank you!
Thanks,
Isaac
thank you
Thanks again for the help, this has been seriously stressing me out!
1) prepare necessary test data with all necessary fields for your case object that you are going to test
2) try to test the extension controller as mentioned below examples (https://developer.salesforce.com/forums/?id=906F00000008y7QIAQ)
test method
3) for figuring out select option test please go through this link (https://developer.salesforce.com/forums/?id=906F00000008zA1IAI)
This would be my best approach to start, if you need any further assistance please go through this link (https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_error_handling.htm)
Let me know, what you tried for writing the test classs and post it here so that i can assist you better
Thank you!