+ Start a Discussion
etechcareersetechcareers 

trying to call a page in testclass but not successfulll????

hi the following is the page reference in my apex controller:

 

public PageReference step3() {
    //Contribution RecordType
    if(rtps=='012S0000000D3Q5IAK'){
        return Page.znewopptystep_Contribution;
    }
    //Contribution - Special Events RecordType
    if(rtps=='012S0000000D3QKIA0'){
        return Page.znewopptystep_Contribution_SpecialEvents;
    }
        return null;
    }

 Here is my test method:

 

    static testMethod void testSaveone() 
  {  
    ZnewOpportunityController ext = new ZnewOpportunityController();
    
    Account acct = ext.getAccount();
    acct.name='sss';
    acct.Org_Recognition_Name__c='UFC';
    acct.Type='Individual';
    acct.Relationship_Stage__c='Lead';
    acct.BillingState='CT';
    acct.BillingStreet='134 Laurel';
    acct.BillingCity='Mineola';
    acct.BillingPostalCode='11501';
    acct.BillingCountry='USA';
    acct.ShippingState = 'CT';
    acct.ShippingCountry = 'USA';
    acct.ShippingPostalCode = '11501';
    acct.ShippingCity = 'Mineola';
    acct.ShippingStreet = '134 Laurel';
    acct.recordtypeid = '012700000005UJ9AAM';
    
    Contact con = ext.getContact();
    con.AccountId = acct.Id;
    con.firstname='jdhjd';
    con.lastname='hdjdhdh';
    con.email='hello@email.com';
    con.phone='5161231234';
    con.recordtypeid = '012700000005ITPAA2';
    
    
    Opportunity opp = ext.getOpportunity();
    opp.Name = 'lslsls';
    opp.Accountid=acct.id;
    opp.stageName='Lead';
    opp.CloseDate=Date.newinstance(2010,12,31);
    opp.Acknowledge_Type__c = 'City';
    opp.Funding_Source__c = 'Individual';
    opp.Public_Private_Funding__c = 'Public';
    opp.StageName = 'Prospect';
    opp.Reinvestment__c = 'Reinvestment';
    opp.FYs_Applied_To__c = 'FY11'; 
    opp.recordtypeid ='012S0000000D3Q5IAK';  
      
   PageReference testprA = Page.znewopptystep_Contribution;
   Test.setCurrentPage(testprA);
  ext.Step3();
}

 Any advice please

 

 

bob_buzzardbob_buzzard

Can you tell us what issue you are seeing? I'm guessing that you are getting an error or code unexpectedly not covered, but it would be better if you give us the details.

Pradeep_NavatarPradeep_Navatar

There is no need in test class to refer any page, it calls automatically on the basis of your condition. For an example PageReference pg = ext.Step3();

 

Hope this helps.

etechcareersetechcareers

Yeah I just noticed that... but because I have so many recordtypes.. It seems like for me to get the coverage I would have to do a spearate testmethod for each page I call with a condition? Is that true..

for example:

I am now on ext.saveone();

 

 

 public PageReference saveone() {
    
    account.phone = contact.phone;
    account.recordtypeid = '012700000005UJ9AAM';
    insert account;
    
    contact.accountId = account.id;
    contact.MailingStreet = account.BillingStreet;
    contact.MailingCity = account.BillingCity;
    contact.MailingPostalCode = account.BillingPostalCode;
    contact.MailingCountry = account.BillingCountry;
    contact.Phone = account.Phone;
    contact.recordtypeid = '012700000005ITPAA2';
    insert contact;
    
    opportunity.accountId = account.id;
    if(rtps=='012700000000vQxAAI'){
        opportunity.recordtypeid = '012700000000vQxAAI';
    }
    //Gift in Kind RecordType
    if(rtps=='012700000005dNoAAI'){
        opportunity.recordtypeid ='012700000005dNoAAI';
    }
    //Matching Gift RecordType
    if(rtps=='012700000005btRAAQ'){
        opportunity.recordtypeid ='012700000005btRAAQ';
    } 
    //Contract Income RecordType
    if(rtps=='012700000005cpHAAQ'){
        opportunity.recordtypeid ='012700000005cpHAAQ';
    }
    //Contribution RecordType
    if(rtps=='012S0000000D3Q5IAK'){
        opportunity.recordtypeid ='012S0000000D3Q5IAK';
    }
    //Contribution - Special Events RecordType
    if(rtps=='012S0000000D3QKIA0'){
        opportunity.recordtypeid ='012S0000000D3QKIA0';
    }
    //Fee for Service RecordType
    if(rtps=='012S0000000D3QFIA0'){
        opportunity.recordtypeid ='012S0000000D3QFIA0';
    } 
    //Honaria RecordType
    if(rtps=='012S0000000D3QUIA0'){
        opportunity.recordtypeid ='012S0000000D3QUIA0';
    }       
    insert opportunity;
return null;
}

 

 

Test class:

 

    static testMethod void testSaveone_Contribution() 
  {  
    ZnewOpportunityController ext = new ZnewOpportunityController();
    
    Account acct = ext.getAccount();
    acct.name='saaaaa';
    acct.Org_Recognition_Name__c='UFC';
    acct.Type='Individual';
    acct.Relationship_Stage__c='Lead';
    acct.BillingState='CT';
    acct.BillingStreet='134 Laurel';
    acct.BillingCity='Mineola';
    acct.BillingPostalCode='11501';
    acct.BillingCountry='USA';
    acct.ShippingState = 'CT';
    acct.ShippingCountry = 'USA';
    acct.ShippingPostalCode = '11501';
    acct.ShippingCity = 'Mineola';
    acct.ShippingStreet = '134 Laurel';
    acct.recordtypeid = '012700000005UJ9AAM';
    
    Contact con = ext.getContact();
    con.AccountId = acct.Id;
    con.firstname='jdhjd';
    con.lastname='hdjdhdh';
    con.email='hello@email.com';
    con.phone='5167111234';
    con.recordtypeid = '012700000005ITPAA2';
    
    
    Opportunity opp = ext.getOpportunity();
    opp.Name = 'lslsls';
    opp.Accountid=acct.id;
    opp.stageName='Lead';
    opp.CloseDate=Date.newinstance(2010,12,31);
    opp.Acknowledge_Type__c = 'City';
    opp.Funding_Source__c = 'Individual';
    opp.Public_Private_Funding__c = 'Public';
    opp.StageName = 'Prospect';
    opp.Reinvestment__c = 'Reinvestment';
    opp.FYs_Applied_To__c = 'FY11'; 
    opp.recordtypeid ='012S0000000D3Q5IAK';  
 
    
    Payment_Detail__c pmt = ext.getPaymentDetail();        
    pmt.Donation__c = opp.Id;
    pmt.Applies_To_FY__c = 'FY11';
    pmt.Date_Due__c = Date.newinstance(2010,12,31);
    pmt.Amount_Due__c =100;
    pmt.Date_Received__c = Date.newinstance(2010,12,31);
    pmt.Amount_Paid__c = 100;
    pmt.Check_Date__c=Date.newinstance(2010,12,31);
    pmt.Check_Number__c='112';
    pmt.Check_Bank__c='hehehe';
    pmt.recordtypeid = '012700000009PxrAAE';
    
    Allocation__c alloc = ext.getAllocation ();    
    alloc.Donation__c = opp.id;
    alloc.Payment_Detail__c = pmt.id;
    alloc.Amount_allocated__c = 100;
    alloc.FY_Allocated_To__c = 'FY11';
    alloc.Program_Location__c = 'Chicago';

    ext.step1();
    ext.step2(); 
    ext.getrectypes();      
    ext.step3a();
    ext.rtps = '012S0000000D3Q5IAK';    
    ext.step3();
    ext.oppid = opp.id;
    ext.getrectypespm();
    ext.step4a();
    ext.rtpspm ='012700000009PxrAAE';   
    ext.step4();     
    ext.getsaname();
    ext.getRole(); 
    ext.saveone();
}

 

 

This one works for when opportunity recordtype is Contribution

Do i have to do the same for Grant, In Kind, etc....

Or can I update the recordtype and call the method ext.saveone() again???