You need to sign in to do that
Don't have an account?
jsacpt24
Test class for external site with attachment
I have a site that is being used internally for our team to submit cases to our admin team. I am trying to write a test class for the apex part of it but my code coverage seems to still be at 0%. Was wondering if someone might be able to help me with this as this is my first test class.
VF:
The controller that I am using for the attachment is being used to save the record, add the attachment and then the page is redirected to a thank you page.
Apex:
I was under the impression that I had to make sure that the test class ran through the required fields of the external site but it doesn't seem to show any test coverage.
Test Class:
Does anyone know what I am doing wrong?
VF:
<apex:page standardController="Case" extensions="case_attachment"> <apex:form id="frm"> <apex:pageBlock title="New Salesforce Case"> <apex:pageBlockSection columns="1" title="Salesforce Case -- Red lines represent required fields." collapsible="false"> </apex:pageBlockSection> <strong>Please click the lookup icon (small button to right of field) to search name selection from Salesforce lookup dialog.</strong> <apex:pageBlockSection columns="1"> <apex:inputField value="{!Case.Requestor_Name__c}" required="true"/> <br></br> </apex:pageBlockSection> <strong>Select Problem and High Priority ONLY if the issue is preventing you from continuing work in Salesforce.</strong> <apex:pageBlockSection columns="1"> <apex:inputField value="{!Case.Type}" required="true"/> <apex:inputField value="{!Case.Priority}" required="true"/> </apex:pageBlockSection> <apex:pageBlockSection columns="1" title="Case Details" collapsible="false"> <apex:inputField value="{!Case.Department__c}" required="true"/> <apex:inputField value="{!Case.Salesforce_Object__c}" required="true"/> <apex:inputField value="{!Case.Description}" required="true" style="width:50%; height: 60px" /> </apex:pageBlockSection> <apex:pageBlockButtons > <apex:commandButton action="{!save}" value="Submit"/> <apex:commandButton action="{!cancel}" value="Cancel"/> </apex:pageBlockButtons> <apex:pageBlockSection title="Upload the Attachment" collapsible="false" dir="LTR" columns="1"> <div id="upload" class="upload"> <apex:inputFile id="fileToUpload" value="{!fileBody}" filename="{!fileName}" styleClass="input-file"/> </div> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
The controller that I am using for the attachment is being used to save the record, add the attachment and then the page is redirected to a thank you page.
Apex:
public class case_attachment { public case objcase{get;set;} public Attachment myAttachment{get;set;} public string fileName{get;set;} public Blob fileBody{get;set;} public case_attachment(Apexpages.standardcontroller controller) { objcase = (Case)controller.getRecord(); myAttachment = new Attachment(); } public pagereference save() { if(myAttachment.Name == null) { insert objcase; } if(myAttachment.Name != null) { insert objcase; System.debug('@@@@@fileBody'+fileBody); myAttachment = new Attachment(); Integer i=0; myAttachment .clear(); myAttachment.Body = fileBody; myAttachment.Name = fileName ; myAttachment.ParentId = objcase.id; insert myAttachment; } pagereference pr = Page.Thank_You; pr.setRedirect(true); return pr; } }
I was under the impression that I had to make sure that the test class ran through the required fields of the external site but it doesn't seem to show any test coverage.
Test Class:
@isTest private class Test_case_attachment { @isTest static void createCase() { Case c = new Case(); c.Requestor_Name__c = '0035C000001njRp'; c.Type = 'Problem'; c.Priority = '1'; c.Department__c = 'Marketing'; c.Salesforce_Object__c = 'Accounts'; c.Description = 'this is a test submission'; insert c; } }
Does anyone know what I am doing wrong?