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
An_dyAn_dy 

Code coverage for wrapper class

Hi,

  Iam trying to get atleast 75% coverage for my VF page but not sure what's wrong it's only giving me 46%, any help would be appreciated.

 

VF:

<apex:page controller="AutomobileDashboard" sidebar="false">

 <h1>Accounts with Related Opporunities</h1>
<apex:form >
<apex:pageBlock id="table"  >
<apex:repeat value="{!accttree}" var="a" id="table">
        <apex:pageblockSection title="{!a.Name}" columns="1">
  <table width="100%" cellpadding ="0" cellspacing = "0">                        
 <tr>
  <th>Name</th>
  <th>Close Date</th>
  <th>Description</th>
  <th>Region</th>
  <th>Status</th>
  <th>Amount</th>
  </tr>   
 <tr>
 <td width='5%'></td>
 <td width='5%'></td>
 <td width='50%'></td>
 <td width='5%'></td>
 <td width='5%'></td>
 <td width='5%'></td>
 </tr>
           <apex:repeat value="{!a.opps}" var="c">
            <tr>
             <td><table> <apex:outputlink value="/{!c.id}" target="_blank">
             <apex:outputtext value="{!c.Name}"/>
            </apex:outputlink></table></td>
             <td><table><apex:outputText label="" value="{0,date,MM/dd/yyyy}"><apex:param value="{!c.CloseDate}" /></apex:outputText></table></td>
             <td><table><apex:outputText label="" value="{!c.Description}"/></table></td>
             <td><table><apex:outputText label="" value="{!c.Region__c}"/></table></td>
             <td><table><apex:outputText label="" value="{!c.Status__c}" escape="false"/></table></td>
             <td><table><apex:outputText label="" value="{0,number, ###,###,###,###}">
                         <apex:param value="{!c.Amount}"/>
                        </apex:outputText></table></td>
            </tr>
           </apex:repeat>
 </table>
 </apex:pageblockSection>
    </apex:repeat>
   </apex:pageBlock>
           </apex:form>
</apex:page>

 

 

Apex Class:

 

public class AutomobileDashboard{

    public List<cAccts> getAccttree() {
        Set<ID> conID = new Set<ID>{};
        for(Opportunity c:[select Id,Name, AccountId, Status__c, Dashboard__c, Description, Region__c, Amount, CloseDate FROM Opportunity where Dashboard__c = true and accountid<>null limit 100]){
            conID.add(c.accountid);
        }
        for(Account a:[select id,Name,(select id,name from opportunities) from Account where id in :conID]){
            retAccts.add(new cAccts(a));
        }  
        return retAccts;
    }

    public List<cAccts> retAccts = new List<cAccts>{};
    public class cAccts{
       public String Name {get; set;}
       public List<Opportunity> opps {get; set;}
       cAccts(Account a){
           Name=a.Name;
           opps=[select Id,Name, AccountId, Status__c, Dashboard__c, Description, Region__c, Amount, CloseDate from Opportunity where accountid =:a.id];
       }
    }

}

 

Test Class:

 

@istest
public class dashboardtestclass{

    static testMethod void theTests(){
    
      Account acc = new Account(name='test account',Vertical_Market__c ='Automotive');
      insert acc;
      
      Opportunity opp = new Opportunity(name='test opp',AccountId = acc.id,CurrencyIsoCode='USD',CloseDate = system.Today(),StageName='Discovery/Prospecting');
      
      insert opp;
      
     AutomobileDashboard sno = new AutomobileDashboard();
      sno.getAccttree();
       
        
     }
    
  }

SamReadySamReady

I plugged this test class into my DE and got 100% code coverage...are you sure that the 46% isn't being effected by other triggers/classes in your org?

 

If you open up the test class and run it in the Developer Console, the Overall Code Coverage panel in the bottom right of the window should show you what might be contributing to your overall Percentage score for test coverage.

An_dyAn_dy
Hey Sam,My bad I didn't include all fields in my Test class, now it's showing me 100%.. thanks for the reply