• nr123
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 3
    Replies

I have a very small class that queries 2 objects and displays resullts on a visualforce page. I am having trouble writing the test for this class. Any suggestions would be greatly appreciated. I am getting 0 coverage right now. This is the class that I am trying to test:

 

public with sharing class ReassignController {

    //query for cases that are unassigned
    public List<Opportunity> getUCases() {
        return [SELECT Level_1_Case_Number__c, Name, Id, Worksite_Core__c, Received_Date_Case__c, CIS_Rep__c 
                FROM Opportunity
                WHERE CIS_Rep__c = null  
                    AND Level_1_Case_Number__c !=null 
                    AND Received_Date_Case__c > :date.parse('1/1/2011') ];
    }

     //query for Amendments that are unassigned
    public List<Amendment__c> getUAmends(){
        return [SELECT Level_1__c, Name, CIS__c, Id,AmendmentInstructions__c, Requested_Date__c 
                FROM Amendment__c 
                WHERE   CIS__c='' 
                AND Completed_Date__c = null 
                AND  DeclinedDate__c=null
                AND Requested_Date__c > :date.parse('1/1/2011')];
    }
   
}

 Thanks.

 

  • September 12, 2011
  • Like
  • 0

I currently have 69% test coverage on the calls. The only code left in the class to test is the constructor. Any suggestions would be greatly appreciated.

Here is the Class: It is basically is just displaying query results for a dashboard:

 

 

public with sharing class retrieveQuotedata {
    Public Date lastbusinessday;
    Public Datetime lastBDtime;
    Public String LBDS;
    Public Date getLastBusinessDay(){
    BusinessHours bh = [select id from businesshours where IsDefault=true];
    Date MyDate = date.today();
    Datetime startTime = Datetime.valueOf(MyDate +' 00:00:00');
    Datetime lastBDTime = BusinessHours.add(bh.id, startTime, (-24 * 60 * 60 * 1000L)); 
    lastbusinessday = date.newinstance(lastBDtime.year(), lastBDtime.month(), lastBDtime.day());  
    if(MyDate == MyDate.tostartofweek()+1){
        lastbusinessday-= 1;
        }
    //LBDS = lastbusinessday.format();
    return lastbusinessday;
    }

    public class QuotesRecvd{

        Public String quotecount {get; set;}
        Public String oId {get;set;}
        Public String OName {get;set;}
        
        public QuotesRecvd(string n ,string q){     
            this.oName = n;
            this.quotecount = q;  
        }
        
        public QuotesRecvd(string n ,string q, string o){     
            this.oName = n;
            this.quotecount = q; 
            this.oid = o;
        }
 
    }
       public List<QuotesRecvd> QuotesRecvdList = new List<QuotesRecvd>();    
       
           public List<QuotesRecvd> getQuotesRecvdCount(){

              AggregateResult[] agr = [SELECT Owner.Name, count(Name) FROM Opportunity WHERE RecordtypeId = '012500000009RqP' AND Version__c = 'TSC Original Quote' AND Quote_Requested__c = :getLastBusinessDay() Group By rollup (Owner.Name) LIMIT 100];
           for(AggregateResult qrcvd : agr){

               QuotesRecvdList.add(new QuotesRecvd(String.valueof(qrcvd.get('Name')),String.valueof(qrcvd.get('expr0'))));
               }  
               return QuotesRecvdList;         
        }
}

 

 

 

Here is what i have so far for test code: (i'm at 69% so far)

 

 

 

 

@isTest
Private class testretrieveQuotedata{
       static testMethod void insertOpps(){    
          //First, create account for the test data
          retrieveQuotedata qs = new retrieveQuotedata();
          Account acct = new Account(name='test account');
          
          insert acct;
           //create an opportunity record
          Opportunity[] opptsToCreate = new Opportunity[]{};
          
          for(Integer i=0; i<1;i++){
              Opportunity oppt = new Opportunity(AccountId=acct.Id, RecordTypeId='012500000009RqP',Name ='testing trigger', Quote_requested__c = qs.getlastbusinessday(), CloseDate = date.parse('9/1/2011'), StageName = '0-Quote Request');
              opptsToCreate.add(oppt);
          }
          insert opptsToCreate;

          for(Opportunity o:opptsToCreate){
          o.Info_Requested_CB__c = true;
          o.Missing_info_requested__c = qs.getlastbusinessday();
          o.Pending_Codes__c = 'IT';
        //  o.Quote_Sent_CB__c = true;
          o.Quote_sent_date__c = qs.getlastbusinessday();
          o.due_date__c = date.today();
          o.quote_id__c = '99999-9';
          o.Lead_Convert__c = true;

          }
          update opptsToCreate;
    }
     
    static testMethod void testgetQuotesRecvdCount(){
          // instantiate the class under test
      retrieveQuotedata qs = new retrieveQuotedata();
         
      List<retrieveQuotedata.QuotesRecvd> QuotesRecvdList = qs.getQuotesRecvdCount();

      System.assertEquals(0, QuotesRecvdList.size());
   }
}

 

 

 

 

 

Thank you.

 

 

  • June 13, 2011
  • Like
  • 0

I need to display a summary of Opportunities by Opportunity Owner in a Visualforce Page Dashboard component. So far I can get it to group by OwnerId, but it doesnt work for Owner.Name. I get the following error: "System.SObjectException: Invalid field Owner.Name for AggregateResult".

 

 

 

public class QuotesRecvd{

    Public String quotecount {get; set;}
    Public String OName {get;set;}
    
    public QuotesRecvd(string n ,string q){     
        this.oName = n;
        this.quotecount = q;
        
    }
}

       public List<QuotesRecvd> QuotesRecvdList = new List<QuotesRecvd>();    
           public List<QuotesRecvd> getQuotesRecvdCount(){
       
              AggregateResult[] agr = [SELECT Owner.Name, count(Name)FROM Opportunity WHERE Quote_Requested__c = :date.today()-1 Group By rollup (Owner.Name)];
           for(AggregateResult qrcvd : agr){
               QuotesRecvdList.add(new QuotesRecvd(String.valueof(qrcvd.get('Owner.Name')),String.valueof(qrcvd.get('expr0'))));
               }
               return QuotesRecvdList;
        
}

 

Any suggestions? I also need to know how to create a test for this.

 

 

Any help would be greatly appreciated!

 

  • June 11, 2011
  • Like
  • 0

I have a very small class that queries 2 objects and displays resullts on a visualforce page. I am having trouble writing the test for this class. Any suggestions would be greatly appreciated. I am getting 0 coverage right now. This is the class that I am trying to test:

 

public with sharing class ReassignController {

    //query for cases that are unassigned
    public List<Opportunity> getUCases() {
        return [SELECT Level_1_Case_Number__c, Name, Id, Worksite_Core__c, Received_Date_Case__c, CIS_Rep__c 
                FROM Opportunity
                WHERE CIS_Rep__c = null  
                    AND Level_1_Case_Number__c !=null 
                    AND Received_Date_Case__c > :date.parse('1/1/2011') ];
    }

     //query for Amendments that are unassigned
    public List<Amendment__c> getUAmends(){
        return [SELECT Level_1__c, Name, CIS__c, Id,AmendmentInstructions__c, Requested_Date__c 
                FROM Amendment__c 
                WHERE   CIS__c='' 
                AND Completed_Date__c = null 
                AND  DeclinedDate__c=null
                AND Requested_Date__c > :date.parse('1/1/2011')];
    }
   
}

 Thanks.

 

  • September 12, 2011
  • Like
  • 0

I currently have 69% test coverage on the calls. The only code left in the class to test is the constructor. Any suggestions would be greatly appreciated.

Here is the Class: It is basically is just displaying query results for a dashboard:

 

 

public with sharing class retrieveQuotedata {
    Public Date lastbusinessday;
    Public Datetime lastBDtime;
    Public String LBDS;
    Public Date getLastBusinessDay(){
    BusinessHours bh = [select id from businesshours where IsDefault=true];
    Date MyDate = date.today();
    Datetime startTime = Datetime.valueOf(MyDate +' 00:00:00');
    Datetime lastBDTime = BusinessHours.add(bh.id, startTime, (-24 * 60 * 60 * 1000L)); 
    lastbusinessday = date.newinstance(lastBDtime.year(), lastBDtime.month(), lastBDtime.day());  
    if(MyDate == MyDate.tostartofweek()+1){
        lastbusinessday-= 1;
        }
    //LBDS = lastbusinessday.format();
    return lastbusinessday;
    }

    public class QuotesRecvd{

        Public String quotecount {get; set;}
        Public String oId {get;set;}
        Public String OName {get;set;}
        
        public QuotesRecvd(string n ,string q){     
            this.oName = n;
            this.quotecount = q;  
        }
        
        public QuotesRecvd(string n ,string q, string o){     
            this.oName = n;
            this.quotecount = q; 
            this.oid = o;
        }
 
    }
       public List<QuotesRecvd> QuotesRecvdList = new List<QuotesRecvd>();    
       
           public List<QuotesRecvd> getQuotesRecvdCount(){

              AggregateResult[] agr = [SELECT Owner.Name, count(Name) FROM Opportunity WHERE RecordtypeId = '012500000009RqP' AND Version__c = 'TSC Original Quote' AND Quote_Requested__c = :getLastBusinessDay() Group By rollup (Owner.Name) LIMIT 100];
           for(AggregateResult qrcvd : agr){

               QuotesRecvdList.add(new QuotesRecvd(String.valueof(qrcvd.get('Name')),String.valueof(qrcvd.get('expr0'))));
               }  
               return QuotesRecvdList;         
        }
}

 

 

 

Here is what i have so far for test code: (i'm at 69% so far)

 

 

 

 

@isTest
Private class testretrieveQuotedata{
       static testMethod void insertOpps(){    
          //First, create account for the test data
          retrieveQuotedata qs = new retrieveQuotedata();
          Account acct = new Account(name='test account');
          
          insert acct;
           //create an opportunity record
          Opportunity[] opptsToCreate = new Opportunity[]{};
          
          for(Integer i=0; i<1;i++){
              Opportunity oppt = new Opportunity(AccountId=acct.Id, RecordTypeId='012500000009RqP',Name ='testing trigger', Quote_requested__c = qs.getlastbusinessday(), CloseDate = date.parse('9/1/2011'), StageName = '0-Quote Request');
              opptsToCreate.add(oppt);
          }
          insert opptsToCreate;

          for(Opportunity o:opptsToCreate){
          o.Info_Requested_CB__c = true;
          o.Missing_info_requested__c = qs.getlastbusinessday();
          o.Pending_Codes__c = 'IT';
        //  o.Quote_Sent_CB__c = true;
          o.Quote_sent_date__c = qs.getlastbusinessday();
          o.due_date__c = date.today();
          o.quote_id__c = '99999-9';
          o.Lead_Convert__c = true;

          }
          update opptsToCreate;
    }
     
    static testMethod void testgetQuotesRecvdCount(){
          // instantiate the class under test
      retrieveQuotedata qs = new retrieveQuotedata();
         
      List<retrieveQuotedata.QuotesRecvd> QuotesRecvdList = qs.getQuotesRecvdCount();

      System.assertEquals(0, QuotesRecvdList.size());
   }
}

 

 

 

 

 

Thank you.

 

 

  • June 13, 2011
  • Like
  • 0

I need to display a summary of Opportunities by Opportunity Owner in a Visualforce Page Dashboard component. So far I can get it to group by OwnerId, but it doesnt work for Owner.Name. I get the following error: "System.SObjectException: Invalid field Owner.Name for AggregateResult".

 

 

 

public class QuotesRecvd{

    Public String quotecount {get; set;}
    Public String OName {get;set;}
    
    public QuotesRecvd(string n ,string q){     
        this.oName = n;
        this.quotecount = q;
        
    }
}

       public List<QuotesRecvd> QuotesRecvdList = new List<QuotesRecvd>();    
           public List<QuotesRecvd> getQuotesRecvdCount(){
       
              AggregateResult[] agr = [SELECT Owner.Name, count(Name)FROM Opportunity WHERE Quote_Requested__c = :date.today()-1 Group By rollup (Owner.Name)];
           for(AggregateResult qrcvd : agr){
               QuotesRecvdList.add(new QuotesRecvd(String.valueof(qrcvd.get('Owner.Name')),String.valueof(qrcvd.get('expr0'))));
               }
               return QuotesRecvdList;
        
}

 

Any suggestions? I also need to know how to create a test for this.

 

 

Any help would be greatly appreciated!

 

  • June 11, 2011
  • Like
  • 0