You need to sign in to do that
Don't have an account?
Shawn Reichner 29
Test class for Visualforce Extension
Hello all Awesome Developers!
I have a visualforce page using an extension that populates a lookup field and does a custom save to redirect to another Visualforce page.
My stuggle is that I am newer to APEX coding and I do not know how to attempt a test class to make my extension class pass code coverage.
Can anyone help please?
Visualforce Page:
Extension Class that Test class is needed for:
Thank you all for your help in getting me past this, I really appreciate it,
Shawn
I have a visualforce page using an extension that populates a lookup field and does a custom save to redirect to another Visualforce page.
My stuggle is that I am newer to APEX coding and I do not know how to attempt a test class to make my extension class pass code coverage.
Can anyone help please?
Visualforce Page:
<apex:page standardController="Salesforce_Support_Survey__c" sidebar="false" showHeader="false" extensions="SalesforceSupportSurveyController" docType="html-5.0"> <style> html, body, p { font-family: "ProximaNovaSoft-Regular", Calibri, "Gill Sans", "Gill Sans MT", Candara, Segoe, "Segoe UI", Arial, sans-serif; font-size: 110%; } input { font-size: 95%; } </style> <apex:form > <apex:pageBlock title="Thank you for taking our short survey!" mode="edit"> <apex:pageBlockButtons > <apex:commandButton action="{!save}" value="Submit Survey"/> </apex:pageBlockButtons> <apex:pageBlockSection title="Survey Questions:" columns="2"> <apex:outputField value="{!Salesforce_Support_Survey__c.X1_Timliness__c}"/> <apex:inputField value="{!Salesforce_Support_Survey__c.X1_Answer__c}"/> <apex:outputField value="{!Salesforce_Support_Survey__c.X2_Satisfaction__c}"/> <apex:inputField value="{!Salesforce_Support_Survey__c.X2_Answer__c}"/> <apex:outputField value="{!Salesforce_Support_Survey__c.X3_Submission_process__c}"/> <apex:inputField value="{!Salesforce_Support_Survey__c.X3_Answer__c}"/> <apex:outputField value="{!Salesforce_Support_Survey__c.X4_Enhancement_Ideas__c}"/> <apex:inputField value="{!Salesforce_Support_Survey__c.X4_Answer__c}"/> <apex:outputField value="{!Salesforce_Support_Survey__c.X5_Additional_Comments__c}"/> <apex:inputField value="{!Salesforce_Support_Survey__c.X5_Answer__c}"/> <apex:outputField value="{!Salesforce_Support_Survey__c.Issue__c}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
Extension Class that Test class is needed for:
public class SalesforceSupportSurveyController { Salesforce_Support_Survey__c Issue {get;set;} //constructor public SalesforceSupportSurveyController(ApexPages.StandardController stdController){ Issue = (Salesforce_Support_Survey__c)stdController.getRecord(); Issue.Issue__c = ApexPages.currentPage().getParameters().get('lookupVal'); } public PageReference save(){ insert Issue; PageReference reRend = new PageReference('/apex/ThankYou'); reRend.setRedirect(true); return reRend; } }
Thank you all for your help in getting me past this, I really appreciate it,
Shawn
NOTE:-
1) You dnt need to create Salesforce_Support_Survey__c object record as same will created in save method.
2) You need to create Issue__c object base on data type to populate below value
try to update your code like below Let us know if this will help you
All Answers
Error:
System.DmlException: Insert failed. First exception on row 0 with id a1nS0000000TaqQIAS; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]
Stack trace:
Class.SalesforceSupportSurveyController.save: line 12, column 1
Class.SalesforceSupportSurveyControllerTest.testMethod1: line 19, column 1
NOTE:-
1) You dnt need to create Salesforce_Support_Survey__c object record as same will created in save method.
2) You need to create Issue__c object base on data type to populate below value
try to update your code like below Let us know if this will help you