You need to sign in to do that
Don't have an account?

Need help with test class for vf page controller
Hello everyone, I'm new to Salesforce. I would appreciate if any one help me how to write test class for my visualforce pages. Below is the controller. I have two visualforce pages QRcase (output) and QRcaseEdit (input/edit). These pages are used to create cases for service related issues of our customers. Could any one please help me with the logic. Thank you!
public class QRreportController /* --------------------- variable for the standard controller ------------------------------- */ { private ApexPages.StandardController std; /* --------------------- variable for this case ------------------------------- */ public Case c {get; set;} /* -------------------- standard work order controller ---------------------------- */ public QRreportController (ApexPages.StandardController stdCtrl) { // prepopulates some fields on page load this.c = (Case)stdCtrl.getRecord(); Map<ID,Schema.RecordTypeInfo> rt_Map = Case.sObjectType.getDescribe().getRecordTypeInfosById(); Id RecordTypeIdCase = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Quality Report Case').getRecordTypeId(); Id rtId = RecordTypeIdCase; c.RecordTypeId=rtId; c.AccountId=System.currentPageReference().getParameters().get('AccountId'); std=stdCtrl; } /* --------------------- Get Case ------------------------------- */ public Case getCase() { return (Case) std.getRecord(); } public Attachment attachment { get { if (attachment == null) attachment = new Attachment(); return attachment; } set; } /* --------------------- Save and Exit method ------------------------------- */ public PageReference saveAndExit() { std.save(); PageReference pageRef1 = new PageReference('/' + getCase().id); return pageRef1; } /* --------------------- Edit method ------------------------------- */ public PageReference edit1() { PageReference pageRef2 = Page.QRcaseEdit; pageRef2.getParameters().put('id', getCase().id); pageRef2.getParameters().put('AccountId', getCase().AccountId); return pageRef2; } /* --------------------- Quick Save method ------------------------------- */ public PageReference save() { std.save(); PageReference pageRef2 = Page.QRcase; ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'SUCCESS! Changes saved.')); pageRef2.getParameters().put('id', getCase().id); pageRef2.getParameters().put('AccountId',getCase().AccountId); return pageRef2; } public PageReference upload() { attachment.OwnerId = UserInfo.getUserId(); attachment.ParentId = getCase().Id ;// the record the file is attached to attachment.IsPrivate = true; try { insert attachment; } catch (DMLException e) { ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment')); return null; } finally { attachment = new Attachment(); } ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Attachment uploaded successfully')); return null; } }
All Answers
PageReference pageRef = Page.YOURPAGE_Name; Below is my input vf page: