function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SFDC Forum 007SFDC Forum 007 

Test class coverage help

Hi,

 

 I have a wrapper class for which i have written a test class for it, i need some help to cover certain methods in the class which i am experiencing difficulty

 

i have written the methods as follows,

 

// methods need help(warpper class)

public class PdfWrapper{
        public Call_Report__c cr{get;set;}
        public List<PADetails> pernAcctList{get;set;}
        public List<PADetails> pernAcctList2{get;set;}
        public Call_Item__c callitemList{get;set;}
        public List<Customer_Brand__c> customerbrndbbl {get;set;}
        public String baId{get;set;}

 

// method help

 

public class PADetails{
        public List<Contact> cclist{get;set;}
        public String paName{get;set;}
        public String paaccName{get;set;}
        public String paJobTitle{get;set;}
        public String paLastvisit{get;set;}
        public String paBrand1{get;set;}
        public String paBrand2{get;set;}
        public String paBrand3{get;set;}
        public String callObjective1{get;set;}
        public String callObjective2{get;set;}
        public String crdate{get;set;}
    }

 

//Fetching all the person account headers and details dynamically
            PADetailsList=new List<PADetails>();           
            PADetails paDetHeader=new PADetails();
            paDetHeader.paName='Name';
            paDetHeader.paJobTitle='Job Title';
        
           
            if(crList!=null && crList.size()>0 && crList.get(0)!=null && crList.get(0).Date__c!=null){
                paDetHeader.crdate='Time';     
            }else{
                paDetHeader.crdate='';    
            }

 

Thanks in advance

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
amidstcloudamidstcloud

Your Class and all its member are public.. 

 

CallReportExtn.PADetails   CRPAD = new CallReportExtn.PADetails ();

 

Its was showing error earlier . Beacuse its a inner class . You have write the parent when you intialize the instance of the inner class . 

 

then access all the member of the class . then assign the value to them . 

 

CRPAD. cr =  "Call report Object "

 

etc . 

 

 

 

Thanks

Ankit

 

 

All Answers

ManjunathManjunath

Hi,

 

1 Create PADetails instance

2 Set all the properties of the PADetails

3 Create instance of  PdfWrapper

4 set all the properties of the PdfWrapper(PADetails)

 

This should do it.

 

Regards,

Manjunath

 

SFDC Forum 007SFDC Forum 007

wen i tried to initialise padetials i am getting  this error

 

Invalid type: PADetails

 

can u help me with code please , i mean for padetials alone, initialising and its properties.

 

 

Thanks in advance

SFDC Forum 007SFDC Forum 007

//Apex class to generate a PDF from Account view page on button click

//Displays all the business account details, Person account details, brands with related BBL information,time,lastvisit,callobjective

This is my controller
public class CallReportExtn{
    
    public class PdfWrapper{
        public Call_Report__c cr{get;set;}
        public List<PADetails> pernAcctList{get;set;}
        public List<PADetails> pernAcctList2{get;set;}
        public Call_Item__c callitemList{get;set;}
        public List<Customer_Brand__c> customerbrndbbl {get;set;}
        public String baId{get;set;}
    }
    public class PADetails{
        public List<Contact> cclist{get;set;}
        public String paName{get;set;}
        public String paaccName{get;set;}
        public String paJobTitle{get;set;}
        public String paLastvisit{get;set;}
        public String paBrand1{get;set;}
        public String paBrand2{get;set;}
        public String paBrand3{get;set;}
        public String callObjective1{get;set;}
        public String callObjective2{get;set;}
        public String crdate{get;set;}
    }
    set<id> top3bbl =  new set<id>();      
    public String brand1{get;set;}
    public String brand2{get;set;}
    public String brand3{get;set;}
    public list<string> callnames{get;set;}
    public List<Call_Report__c> crList{get;set;}
    public List<Customer_Brand__c> cbList{get;set;}
    public List<PdfWrapper> pdfWrapperList{get;set;}
    public List<PADetails> PADetailsList{get;set;}    
    public String userid=UserInfo.getUserId();
    Map<Id,List<PADetails>> paMap=new Map<Id,List<PADetails>>();
    Map<Id,Call_Item__c> callitempaMap=new Map<Id,Call_Item__c>();
    Map<Id,Call_Report__c> callReppaMap=new Map<Id,Call_Report__c>();
    Map<String,Customer_Brand__c> cCBpaMap=new Map<String,Customer_Brand__c>();
    Map<String,Contact> conmap=new Map<String,Contact>();
    Map<Id,List<PADetails>> cpmap=new Map<Id,List<PADetails>>();
    List<Customer_Brand__c> customerbrnd = new List<Customer_Brand__c>();
    List<Call_Item__c>  calltemplst=new List<Call_Item__c>();
        
        public CallReportExtn(ApexPages.StandardController controller){
        pdfWrapperList=baAccInfo();       
    }
    public List<PdfWrapper> baAccInfo(){
        List<PdfWrapper> pdfWrapper=new List<PdfWrapper>();
        Set<Id> accIdSet=new Set<Id>();
        Set<Id> callplanIdSet=new Set<Id>();
        if(userid !=null)
        //Fetching all the business account fields from call report
        crList=[select id,Contact__c,Date__c,Call_plan__c,Account__r.Name,Account__c,Account__r.id,Account__r.BillingCity,Account__r.BillingStreet,Account__r.BillingState,Account__r.BillingCountry,Account__r.BillingPostalCode,Account__r.phone,Account__r.Type,Account__r.Segment_Status__c,Account__r.Total_Number_Of_Patients__c,Account__r.No_of_Seats__c,Objective__r.Name,Objective2__r.Name from Call_Report__c where CallDate__c=TODAY and OwnerId=:userid];
       System.debug('crList==> '+crList);   
        for(Call_Report__c callRep:crList)
        {
             if(callRep.Account__c !=null)
             {
              if(!accIdSet.contains(callRep.Account__c))
              {
                 accIdSet.add(callRep.Account__c);
                   

                 }
           }
                 
            if(callRep.Call_plan__c !=null)
            {
            if(!callplanIdSet.contains(callRep.Call_plan__c))
            callplanIdSet.add(callRep.Call_plan__c);
              }
              callReppaMap.put(callRep.Contact__c,callRep);   
                             
                                    
        }  
        //Fetching all the person accounts from a list
       List<Account> paList=[select Name,Job_Title__pc,Primary_Customer__pc,id,PersonContactId,Last_Activity__pc  from Account where Primary_Customer__pc in:accIdSet];
       //Fetching the last activity date from contact object
       List<Contact> cclist=[select Last_Activity__c from contact where Last_Activity__c !=null];
        System.debug('cclist ==> '+cclist );
        //Fetching the top three priority brands id callplan is added to callreport  
        if(callplanIdSet.size()>0){
             calltemplst = [select id,Brand__c,Brand__r.name,Position__c,Brand_Call_Plan__c from Call_Item__c where Brand_Call_Plan__c in:callplanIdSet ORDER BY Position__c limit 3];
             System.debug('calltemplst ==> '+calltemplst );        
        }
            
            
      
        for(Id baId:accIdSet){
        //Fetching all the person account headers and details dynamically
            PADetailsList=new List<PADetails>();           
            PADetails paDetHeader=new PADetails();
            paDetHeader.paName='Name';
            paDetHeader.paJobTitle='Job Title';
        
           
            if(crList!=null && crList.size()>0 && crList.get(0)!=null && crList.get(0).Date__c!=null){
                paDetHeader.crdate='Time';     
            }else{
                paDetHeader.crdate='';    
            }
            
           if(calltemplst!=null && calltemplst.size()>0 && calltemplst.get(0)!=null && calltemplst.get(0).Brand__r.name!=''){
                paDetHeader.paBrand1=calltemplst.get(0).Brand__r.name;
                top3bbl.add(calltemplst.get(0).Brand__c);               
                                
            }else{
                paDetHeader.paBrand1='';    
            }
            
            
       
            if(calltemplst!=null && calltemplst.size()>0 && calltemplst.get(0)!=null && calltemplst.get(0).Brand__r.name!=''){
                paDetHeader.paBrand1=calltemplst.get(0).Brand__r.name;
                top3bbl.add(calltemplst.get(0).Brand__c);               
                                
            }else{
                paDetHeader.paBrand1='';    
            }
            
            if(calltemplst!=null && calltemplst.size()>1 && calltemplst.get(1)!=null && calltemplst.get(1).Brand__r.name!=''){
                paDetHeader.paBrand2=calltemplst.get(1).Brand__r.name;  
                top3bbl.add(calltemplst.get(1).Brand__c);                
            }else{
                paDetHeader.paBrand2='';    
            }
            
            if(calltemplst!=null && calltemplst.size()>2 && calltemplst.get(2)!=null && calltemplst.get(2).Brand__r.name!=''){
                paDetHeader.paBrand3=calltemplst.get(2).Brand__r.name;
                top3bbl.add(calltemplst.get(2).Brand__c);               
            }else{
                paDetHeader.paBrand3='';    
            }
            
            
             if(crList!=null && crList.size()>0 && crList.get(0)!=null && crList.get(0).Objective__r.Name!=''){
                paDetHeader.callObjective1='Objective1';     
            }else{
                paDetHeader.callObjective1='';    
            }
            
            if(crList!=null && crList.size()>0 && crList.get(0)!=null && crList.get(0).Objective__r.Name!=''){
                paDetHeader.callObjective2='Objective2';     
            }else{
                paDetHeader.callObjective2='';    
            }
            
             if(cclist!=null){
                paDetHeader.paLastvisit='Lastvisit';     
            }else{
                paDetHeader.paLastvisit='';    
            }
            
           //Fetching the top three brands from customer brand object based on related HCP
       if(top3bbl.size()>0){
           cbList= [select BBL__c,HCP__c,Brand__r.Name from Customer_Brand__c where  Brand__c in:top3bbl and HCP__c in:callReppaMap.keyset()];
           System.debug('cbList==> '+cbList);
           if(cbList.size()>0)
           {
           for(Customer_Brand__c cb:cbList){
               cCBpaMap.put(cb.HCP__c+cb.Brand__r.Name,cb);    
           }
           }
       }
       
      
            
            PADetailsList.add(paDetHeader);
                   
            for(Account ac:paList){
                    System.debug('ac.Name ==> '+ac.Name);
                    PADetails paDet=new PADetails();
                    paDet.paName=ac.Name;
                    if(ac.Primary_Customer__pc !=null)
                    
                    paDet.paJobTitle=ac.Job_Title__pc;
                    
                 if(callReppaMap.get(ac.personContactId)!=null){
                    paDet.crdate=String.valueof(callReppaMap.get(ac.personContactId).Date__c.format('hh:mm'));
                    }else{
                        paDet.crdate='';

                    }
 
                   
                   
                       
                  
                    if(callReppaMap.get(ac.personContactId)!=null){
                        paDet.callObjective1=callReppaMap.get(ac.personContactId).Objective__r.Name;
                    }else{
                        paDet.callObjective1='';

                    }
                    if(callReppaMap.get(ac.personContactId)!=null){
                        paDet.callObjective2=callReppaMap.get(ac.personContactId).Objective2__r.Name;
                    }else{
                        paDet.callObjective2='';

                    }
                    if(calltemplst.size()>0)
                    {
                    if(cCBpaMap.get(ac.personContactId+calltemplst.get(0).Brand__r.name)!=null){
                        paDet.paBrand1=cCBpaMap.get(ac.personContactId+calltemplst.get(0).Brand__r.name).BBL__c;
                    }else{
                        paDet.paBrand1='';

                    }
                    }
                    if(calltemplst.size()>1)
                    {
                    if(cCBpaMap.get(ac.personContactId+calltemplst.get(1).Brand__r.name)!=null){
                        paDet.paBrand2=cCBpaMap.get(ac.personContactId+calltemplst.get(1).Brand__r.name).BBL__c;
                    }else{
                        paDet.paBrand2='';

                    }
                    }
                    if(calltemplst.size()>2)
                    {
                    if(cCBpaMap.get(ac.personContactId+calltemplst.get(2).Brand__r.name)!=null){
                        paDet.paBrand3=cCBpaMap.get(ac.personContactId+calltemplst.get(2).Brand__r.name).BBL__c;
                    }else{
                        paDet.paBrand3='';

                    }
                    }                   
                    if(ac.Last_Activity__pc!=null){
                        System.debug('ac.Last_Activity__pc ==> '+ac.Last_Activity__pc);
                        String str=String.valueOf(ac.Last_Activity__pc);                        
                        paDet.paLastvisit=str.substring(8,10)+'/'+str.substring(5,7)+'/'+str.substring(0,4);
                       
                        
                     }
                     
                     else
                     {
                         paDet.paLastvisit='';
                         
                     }
                     
                 
                     
                     
                     
                    
                     if(ac.Primary_Customer__pc !=null)
                     {
                    if(baId == ac.Primary_Customer__pc)
                    {
                    PADetailsList.add(paDet);
                    paMap.put(baId,PADetailsList);    
                    }
                    }
          }
          
         }
        
         
        if(crList.size()>0){
        Map<String,String> baIdMap=new Map<String,String>();
        for(Call_Report__c callRep:crList){
            if(baIdMap!=null && baIdMap.get(callRep.Account__c)==null){    
                PdfWrapper pw=new PdfWrapper();
                pw.cr=callRep;
                if(callRep.Account__c !=null){
                    baIdMap.put(callRep.Account__c,callRep.Account__c);
                    pw.pernAcctList=paMap.get(callRep.Account__c);
                }
           
                if(callRep.Call_plan__c !=null)
                pw.callitemList=callitempaMap.get(callRep.Call_plan__c);
                pdfWrapper.add(pw);
            }
                                
        }
        }
        
        return pdfWrapper;
    }
    
    

}

 

tell me how to cover the bold highlighted part alone

amidstcloudamidstcloud

Your Class and all its member are public.. 

 

CallReportExtn.PADetails   CRPAD = new CallReportExtn.PADetails ();

 

Its was showing error earlier . Beacuse its a inner class . You have write the parent when you intialize the instance of the inner class . 

 

then access all the member of the class . then assign the value to them . 

 

CRPAD. cr =  "Call report Object "

 

etc . 

 

 

 

Thanks

Ankit

 

 

This was selected as the best answer
SFDC Forum 007SFDC Forum 007

Thanks it worked , I also have another small doubt

 

I am fetching all the headers dynamically with the values correspondingly, i am clueless to cover that part alone,

 

 

for(Id baId:accIdSet){
        //Fetching all the person account headers and details dynamically
            PADetailsList=new List<PADetails>();           
            PADetails paDetHeader=new PADetails();
            paDetHeader.paName='Name';
            paDetHeader.paJobTitle='Job Title';
        
           
            if(crList!=null && crList.size()>0 && crList.get(0)!=null && crList.get(0).Date__c!=null){
                paDetHeader.crdate='Time';     
            }else{
                paDetHeader.crdate='';    
            }
            
           if(calltemplst!=null && calltemplst.size()>0 && calltemplst.get(0)!=null && calltemplst.get(0).Brand__r.name!=''){
                paDetHeader.paBrand1=calltemplst.get(0).Brand__r.n

ame;
                top3bbl.add(calltemplst.get(0).Brand__c);               
                                
            }else{
                paDetHeader.paBrand1='';    
            }

 

 

This is the code where i am fetching the headers dynamically needs to be covered, Please help me with this alone.

 

 

 

Thanks in Advance