+ Start a Discussion

Testing PageReference Classes

I have created a queue that holds data in an object in Salesforce. I have researched others who have had some similar issues but nothing is helping so far. Here is the code for it. I am just not sure how to test it, I have have the code that i tried to test it below as well. Can anyone please help me out.

public class ExceptionsThunderheadUtil { //create apex class ExceptionsEmailtoThunderhead
    List<User> usr = [SELECT id, alias, phone, name,email FROM User WHERE id = :UserInfo.getUserId()];
    public string emRecip;
    public string emSend;
    public string emSub; //email subject
    public string usrNam; //name of user
    public string usrPh; //users phone number
    public string usrEm; // user email address
    public string dlrNam; //dealer name
    public String dlrFax; //dealer fax number
    public String dlrEm; //dealer email
    public String dlrNum;
    public String subj;
    public String remrk1;
    public String remrk2;
    public String remrk3;
    public String remrk4;
    public String remrk5;
    public String remrk6;
    public String remrk7;
    public String remrk8;
    public String remrk9;
    public String remrk10;
    /*Not Sure if remarks are being prepopulated
    public decimal AcqFee;
    public decimal FincAmt;
    public decimal FlatFee;
    public decimal PartPct;
    public decimal PartAmt;
    public string reqProg;
    public string fieldLabel;*/
    public ExceptionsThunderheadUtil(ApexPages.StandardController stdController)
            //Select user info
            List<User> usr = [SELECT id, alias, phone, name,email FROM User WHERE id = :UserInfo.getUserId()];
            usrNam = usr[0].name;
            usrPh = usr[0].phone;
            usrEm =  usr[0].email;
            //select dealer fields
            List<Deal_Exceptions__c> ex = [SELECT Id, Application_Number__c, Dealer_Name__c FROM Deal_Exceptions__c WHERE id = :ApexPages.currentPage().getParameters().get('Id')];
            List<Account> acc = [Select ID, name, Inbound_Fax__c, Email_Address__c,Dealer_Number__c From Account where name = :ex[0].Dealer_Name__c];
            dlrNam = acc[0].name;
            //dlrFax = acc[0].Inbound_Fax__c;
            dlrFax = '877-567-2831';
            //dlrEm = acc[0].Email_Address__c;
            dlrEm = 'jamie.swingle@gmfinancial.com';
            dlrNum = acc[0].dealer_number__c;
            Thunderhead_Queue_Outbound__c rec = new Thunderhead_Queue_Outbound__c();

    public ExceptionsThunderheadUtil()

    public String getDlrNum(){
        return dlrNum;
    public void setDlrNum(String s) {
        dlrNum = s;
    public String getUsrNam(){
        return usrNam;
    public void setUsrNam(String s) {
        usrNam = s;
    public String getUsrPh(){
        return usrPh;
     public void setUsrPh(String s) {
        UsrPh = s;
    public String getUsrEm(){
        return usrEm;
    public void setUsrEm(String s) {
        UsrEm= s;
    public String getdlrNam(){
        return dlrNam;
    public String getdlrFax(){
        return dlrFax;
    public String getDlrEm(){
        return dlrEm;
    public void setDlrEm(String s){
        dlrEm = s;
    public void setdlrNam(String s) {
        dlrNam= s;
      public void setdlrFax(String s) {
        dlrFax = s;
    public String getSubj(){
        return subj;
    public void setSubj(String s){
        subj = s;
    public String getRemrk1(){
        return remrk1;
    public void setRemrk1(string a){
        remrk1 =a;
    public String getRemrk2(){
        return remrk2;
    public void setRemrk2(string b){remrk2 =b;}
    public String getRemrk3(){
        return remrk3;
    public void setRemrk3(string s){remrk3 =s;}
    public String getRemrk4(){return remrk4;}
    public void setRemrk4(string s){remrk4 =s;}
    public String getRemrk5(){return remrk5;}
    public void setRemrk5(string s){remrk5 =s;}
    public String getRemrk6(){return remrk6;}
    public void setRemrk6(string s){remrk6 =s;}
    public String getRemrk7(){return remrk7;}
    public void setRemrk7(string s){remrk7 =s;}
    public String getRemrk8(){return remrk8;}
    public void setRemrk8(string s){remrk8 =s;}
    public String getRemrk9(){return remrk9;}
    public void setRemrk9(string s){remrk9 =s;}
    public String getRemrk10(){return remrk10;}
    public void setRemrk10(string s){remrk10 =s;}
    public PageReference createEmail(){
        //List<Deal_Exceptions__c> ex = [SELECT id, Application_Number__c, Dealer_Name__c FROM Deal_Exceptions__c where id = :exp[0].id];
        //List<Account> acc = [Select ID, name From Account where name = :ex[0].Dealer_Name__c];
        List<Deal_Exceptions__c> ex = [SELECT Id, Application_Number__c, Dealer_Name__c FROM Deal_Exceptions__c WHERE id = :ApexPages.currentPage().getParameters().get('Id')];
        List<Account> acc = [Select ID, name, Inbound_Fax__c, email_address__c, GMF_ACF__c, dealer_number__c  From Account where name = :ex[0].Dealer_Name__c];
        Thunderhead_Queue_Outbound__c em = new Thunderhead_Queue_Outbound__c();// create record in Thunderhead_Queue_Outbound__c
        em.Application_Number__c = ex[0].Application_Number__c;
        em.Dealer_Name__c = ex[0].Dealer_Name__c;
        em.Email_from__c = usr[0].email;
        //em.Email_to__c = acc[0].email_address__c;
        em.Email_to__c = 'jamie.swingle@gmfinancial.com';
        em.dealer_number__c = acc[0].dealer_number__c;
        em.subject__c = subj;
        em.remarks_1__c = remrk1;
        em.remarks_2__c = remrk2;
        em.remarks_3__c = remrk3;
        em.remarks_4__c = remrk4;
        em.remarks_5__c = remrk5;
        em.remarks_6__c = remrk6;
        em.remarks_7__c = remrk7;
        em.remarks_8__c = remrk8;
        em.remarks_9__c = remrk9;
        em.remarks_10__c = remrk10;
        em.Brand_Code__c = acc[0].GMF_ACF__c;
        em.Channel_Indicator__c = 'E';
        em.Letter_Type_Code__c = 'POSTFUND';
        em.Need_To_Send__c = true;
        insert em;
        PageReference reference=new PageReference('https://cs20.salesforce.com/'+ em.id);

        return reference;
    public PageReference createFax(){
        List<Deal_Exceptions__c> ex = [SELECT id, Application_Number__c, Dealer_Name__c FROM Deal_Exceptions__c WHERE id =:ApexPages.currentPage().getParameters().get('Id')];
        List<Account> acc = [Select ID, name, Inbound_Fax__c, email_address__c, GMF_ACF__c, Dealer_Number__c  From Account where name = :ex[0].Dealer_Name__c];
        ThunderHead_Queue_Outbound__c fx = new ThunderHead_Queue_Outbound__c();
        fx.Application_Number__c = ex[0].Application_Number__c;
        fx.Dealer_Name__c = ex[0].Dealer_Name__c;
        fx.dealer_number__c = acc[0].dealer_number__c;
        //Check Deal and Dealer record to grab this info.
        fx.Brand_Code__c = acc[0].GMF_ACF__c;
        fx.Channel_Indicator__c = 'F';
        fx.Fax_From__c = usr[0].name;
        //fx.Fax_Number__c = acc[0].Inbound_Fax__c;
        fx.Fax_To__c = ex[0].Dealer_Name__c;
        fx.Fax_Number__c = '877-567-2831';
        fx.Letter_Type_Code__c = 'POSTFUND';
        fx.Need_To_Send__c = true;
        fx.remarks_1__c = remrk1;
        fx.remarks_2__c = remrk2;
        fx.remarks_3__c = remrk3;
        fx.remarks_4__c = remrk4;
        fx.remarks_5__c = remrk5;
        fx.remarks_6__c = remrk6;
        fx.remarks_7__c = remrk7;
        fx.remarks_8__c = remrk8;
        fx.remarks_9__c = remrk9;
        fx.remarks_10__c = remrk10;
        insert fx;
        PageReference reference=new PageReference('https://cs20.salesforce.com/'+ fx.id);

        return reference;
    //for visualforce page remark counter
    Integer count = 1;
    public PageReference incrementCounter() {
            if(count <10){
            return null;
    public Integer getCount() {
        return count;

-----------------------------------------------------------TEST CLASS BELOW------------------------------------------------------------
public class ExceptionsThunderheadUtilTest{
  public string usrNam {get; set;} //name of user
     public string usrPh {get; set;} //users phone number
     public string usrEm {get; set;} // user email address
     public string dlrNam {get; set;} //dealer name
     public String dlrFax {get; set;} //dealer fax number
     public String dlrEm {get; set;} //dealer email
     public String dlrNum {get; set;}
     public String subj{get; set;}
     public String remrk1{get; set;}
     public String remrk2{get; set;}
     public String remrk3{get; set;}
     public String remrk4{get; set;}
     public String remrk5{get; set;}
     public String remrk6{get; set;}
     public String remrk7{get; set;}
        public String remrk8{get; set;}
     public String remrk9{get; set;}
     public String remrk10{get; set;}
    public ExceptionsThunderheadUtilTest(){
        ExceptionsThunderheadUtil controller = new ExceptionsThunderheadUtil();
        String nextPage = controller.createEmail().getUrl();
        // Verify that page fails without parameters
        System.assertEquals('/apex/failure?error=noParam', nextPage);
        Account acc = new Account(name = 'Test Dealer', Inbound_Fax__c='555-555-5255', email_address__c='testdealer@dealer.com', GMF_ACF__c = 'GMF', dealer_number__c='00000');
        insert acc;
        List<Account> accList = [Select ID From Account Limit 1];
        User usr = new User(phone = '555-555-5555', firstname ='Test',lastname='One',email = 'test@gmf.com');   
     insert usr;
        List<User> usrList = [Select ID From User Limit 1];
        Deal_Exceptions__c ex = new Deal_Exceptions__c();
     insert ex;
        List<Deal_Exceptions__c> exList = [Select ID From Deal_Exceptions__c Limit 1];
        ApexPages.StandardController stc = new ApexPages.StandardController(ex);
        ExceptionsThunderheadUtil eth = new ExceptionsThunderheadUtil(stc);
        controller = new ExceptionsThunderheadUtil();
        controller.UsrNam = 'test';
        System.assertEquals(usrNam, 'test');
  controller.usrEm = 'test2';
        System.assertEquals(usrEm, 'test2');

  controller.dlrNam = 'test3';
        System.assertEquals(dlrNam, 'test3');

  controller.dlrFax = 'test4';
        System.assertEquals(dlrFax, 'test4');

  controller.dlrEm = 'test5';
        System.assertEquals(dlrEm, 'test5'); 
        controller.dlrNum = 'test6';
        System.assertEquals(dlrNum, 'test6');
        controller.usrPh = 'test7';
        System.assertEquals(usrPh, 'test7');
        controller.subj = 'test8';
        System.assertEquals(subj, 'test8');
        controller.remrk1 = 'test9';
        System.assertEquals(remrk1, 'test9');
        controller.remrk2 = 'test10';
        System.assertEquals(remrk2, 'test10');
        controller.remrk3 = 'test11';
        System.assertEquals(remrk3, 'test11');
        controller.remrk4 = 'test12';
        System.assertEquals(remrk4, 'test12');
        controller.remrk5 = 'test13';
        System.assertEquals(remrk5, 'test13');
        controller.remrk6 = 'test14';
        System.assertEquals(remrk6, 'test14');
        controller.remrk7 = 'test15';
        System.assertEquals(remrk7, 'test15');
        controller.remrk8 = 'test16';
        System.assertEquals(remrk8, 'test16');
        controller.remrk9 = 'test17';
        System.assertEquals(remrk9, 'test17');
        controller.remrk10 = 'test18';
        System.assertEquals(remrk10, 'test18');
        nextPage = controller.createEmail().getUrl();
        // Verify that the success page displays
        System.assertEquals('/apex/success', nextPage);

Please see if this helps: http://christopheralunlewis.blogspot.in/2011/08/writing-unit-tests-for-pagereference.html


I went to this page and is had nothing to help me on there.