You need to sign in to do that
Don't have an account?
etechcareers
Need 5% percent to deploy test method please help...urgent
Hi everyone:
Everything is great with my testmethod with the exception that it is not picking up Page Reference Query()???
I cant figure it out:
Here is my apex controller for Page Reference Query();It picks up until If(level=='A') but will not go into aggregate result or passed that... i tried everything in my test method please help.
thanks
Happy holidays
public PageReference query() { Date Lastmonthfirst; Date selectedDate = Date.Today(); //Give your date Lastmonthfirst = selectedDate.toStartOfMonth().addMonths(-1); List<Compensation__c> delmarker = new List<Compensation__c>(); delmarker=[select id from Compensation__c where Date_ran__c =LAST_MONTH]; for(Compensation__c sm:delmarker){ delete sm; } If (Level=='AA'){ AggregateResult[] groupedResults = [SELECT Ownerid, Count(Id) ce FROM Opportunity Where Comp__c=False AND CloseDate=LAST_MONTH AND StageName = 'Closed Won' GROUP BY Ownerid]; queryResults = new List<GrossHolder>(); for (AggregateResult ar : groupedResults) { GrossHolder myObject = new GrossHolder(); myObject.TotalGross = (Integer) ar.get('ce'); Gross = myObject.TotalGross; myObject.compid = String.valueOf(ar.get('Ownerid')); AAid = myObject.compid; getWithdrawn(AAid); getWithdrawnT(AAid); getCustomers(AAid); /*****************************INSERT COMP**********************************************************************/ Compensation__c cmp = new Compensation__c(); cmp.Name__c = AAid; cmp.Comp_Plan__c ='AA'; cmp.Total_Gross__c = Gross; cmp.Date_ran__c = Lastmonthfirst; if(AAWid!=AAid){ cmp.Total_Withdrawn__c = 0; } else{ cmp.Total_Withdrawn__c = Withdrawn; if(cmp.Total_Withdrawn__c == null){ cmp.Total_Withdrawn__c = 0; } } if(AATid!=AAid){ cmp.Total_Transfers__c = 0; } else{ cmp.Total_Transfers__c = Transferred; if(cmp.Total_Transfers__c == null){ cmp.Total_Transfers__c = 0; } } if(AACSid!=AAid){ cmp.Total_Customers__c = 0; } else{ cmp.Total_Customers__c = Customers; if(cmp.Total_Customers__c == null){ cmp.Total_Customers__c = 0; } } insert cmp; queryResults.add(myObject); } } return null; }
Here is my test class:
@isTest(SeeAllData=true) private class compensationreport_TestMethod // Name of the test class, Can be any name { static testmethod void compensationreport_TestMethod(){ // Name of the test method. Must be the same as the class name Date Lastmonthfirst; Date selectedDate = Date.Today(); //Give your date Lastmonthfirst = selectedDate.toStartOfMonth().addMonths(-1); //Set up user User u1 = [SELECT Id FROM User WHERE Alias='ZishanR']; System.runAs(u1) { Compensation__c cc = new Compensation__c ( Total_Gross__c = 120, Total_Withdrawn__c = 10, Total_Transfers__c = 0, Comp_Plan__c = 'AA', Total_Customers__c = 127, Name__c = u1.Id, Date_ran__c = Lastmonthfirst ); insert cc; Account a = new Account(); a.firstName = 'lisa'; a.Lastname = 'stevenlee'; a.PersonLeadSource = 'Other'; a.PersonEmail = 'choosepros123@iintest.com'; a.PersonBirthdate = date.newinstance(1974,10,11); a.Birthday__c = date.newinstance(1974,10,11); a.CreatedDate = Lastmonthfirst; a.ownerid = u1.id; a.BillingStreet = '128 new st'; a.BillingCity = 'New York'; a.BillingState = 'NY'; a.BillingCountry = 'USA'; a.BillingPostalCode = '10061'; insert a; System.Debug('yes' + a.CreatedDate + a.id + a.Ownerid + a.Owner.Level__c); Opportunity o = new Opportunity(); o.Accountid = a.id; o.Name = 'IInTest - HTCP Jan 2012'; o.CloseDate = Lastmonthfirst; o.StageName = 'Closed Won'; o.Comp__c = False; o.LeadSource = 'Natural Healers'; o.Type = 'Re-enrollment'; Opportunity oWT = new Opportunity(); oWT.Accountid = a.id; owT.Name = 'IINTestWT - HTCP Jan 2012'; owT.CloseDate = Lastmonthfirst; owT.Withdrawn_Date__c = Lastmonthfirst; owT.StageName = 'Closed Won'; owT.Withdrawn__c = True; owT.LeadSource = 'Natural Healers'; owT.Withdrawal_Status__c = 'Transferred to DL'; owT.Refunded_Amount__c = 3100; owT.Withdrawal_Fee__c = 100; Opportunity oW2 = new Opportunity(); oW2.Accountid = a.id; ow2.Name = 'IINTestW2 - HTCP Jan 2012'; ow2.CloseDate = Lastmonthfirst; ow2.Withdrawn_Date__c = Lastmonthfirst; ow2.StageName = 'Closed Won'; ow2.Withdrawn__c = True; ow2.LeadSource = 'Natural Healers'; ow2.Withdrawal_Status__c = 'Withdrawn'; ow2.Refunded_Amount__c = 3100; ow2.Withdrawal_Fee__c = 100; ow2.Withdrawal_Reason_Further_Detail__c = 'this is my test'; Account ac = new Account(); ac.firstName = 'lisa'; ac.Lastname = 'stevenleered'; ac.PersonLeadSource = 'Other'; ac.PersonEmail = 'choosepros1234@iintest.com'; ac.PersonBirthdate = date.newinstance(1974,10,11); ac.Birthday__c = date.newinstance(1974,10,11); ac.CreatedDate = Lastmonthfirst; ac.ownerid = u1.id; ac.BillingStreet = '127 new st'; ac.BillingCity = 'New York'; ac.BillingState = 'NY'; ac.BillingCountry = 'USA'; ac.BillingPostalCode = '10061'; //Use the PageReference Apex class to instantiate a page compensationreport testcls = new compensationreport(); // Initialize variable for original class Test.startTest(); testcls = new compensationreport(); String AAid = u1.id; System.Debug('URL' + Page.comp_run.getURL()); //system.assertEquals(Expected,actual); insert o; insert owT; insert ow2; // Call Function of Original class Opportunity oop = [Select ownerid, id from Opportunity where id=: o.id]; testcls.getGrossHolder(oop.ownerid); testcls.getWithdrawn(oop.ownerid); testcls.getWithdrawnT(oop.ownerid); insert ac; Account abc = [Select Ownerid,id from Account where id=:ac.id]; testcls.getCustomers(abc.Ownerid); testcls.query(); Compensation__c cmp = new Compensation__c(); cmp.Name__c = AAid; cmp.Comp_Plan__c ='AA'; cmp.Total_Gross__c = 1; cmp.Date_ran__c = Lastmonthfirst; cmp.Total_Withdrawn__c = 1; cmp.Total_Transfers__c = 1; cmp.Total_Customers__c = 1; insert cmp; Test.stopTest(); } } }
Hi,
I think you are not assigning any value to 'Level' variable which you are checking in first If condition in the test class.
Please assign value to this variable and check again.
Regard,
Sridhar Bonagiri