You need to sign in to do that
Don't have an account?
Isaac Gomolka
Please Help with Extension Test Class
Hi everybody, I have been struggling trying to make a test class for the extension class I have made. I would really greatly appreciate it if someone could show me what my test class would be. I have tried to get help before but people just send me the salesforce link explaining a test class with extensions, but I have read it and still don't understand. I have done tons of research, but just don't get test classes. Seeing how this test class would look would greatly help me understand it as well.
Thanks for the help in advanced!
-Isaac
Extension Class:
Visualforce Page:
Thanks for the help in advanced!
-Isaac
Extension Class:
*************************************************************** * 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 ApexPages.StandardController ctrl; public EscalationPageExtension(ApexPages.StandardController controller) { ctrl = controller; } 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() { Case cas = (Case)ctrl.getRecord(); cas.Escalation_Data_Integrity__c = Boolean.valueof(picklist1); } public void setViableWorkaround() { Case cas = (Case)ctrl.getRecord(); cas.Escalation_Viable_Workaround__c = Boolean.valueof(picklist2); } public void setAppFunction() { Case cas = (Case)ctrl.getRecord(); cas.Escalation_Application_Functionality__c = Boolean.valueof(picklist3); } }
Visualforce 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>
I will recommend you to start using trailhead to learn about test classes
1) https://trailhead.salesforce.com/modules/apex_testing
Also please check below post
1) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
2) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_example.htm
Pleasse check below post sample test class
1) http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html
You write a test class for this the same way that you would any other:
- Set up some data for the Controller to access (No need in this case)
- Instantiate the Controller- .
- Execute a method/methods
- Verify the behaviour with asserts.
Let us know if this will help you
Hi Amit, I really appreciate the help. I had a question, wondering if you could help. How would I test if the visualforce page saves? Like if i input all the fields for the required fields and I want to test that the page would save, how would I do this? Thanks again for the help!
-Isaac