• Irwin3017
  • NEWBIE
  • 0 Points
  • Member since 2013

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

I'm just getting started with Apex and am having a little trouble getting my first test class past 57%. The test is for a very simple custom controller for a visualforce page which returns a list of values from an SOQL query, then updates any records that are modified. The controller works fine, and I've poured over all the developer documentation and board posts I can find but still can't get the test to fly.

 

I intend to improve my Apex knowledgebase with some additional training but in the meantime really need to get this one class up and running. Any help would be greatly appreciated. My current code is below:

 

Custom Controller:

public class plantListingClass {
  
    public Account[] accts = new Account[0];

  public Account[] getAccts() {
        
        accts = [SELECT ID, Parent.Name, Name, BillingState, Logo__c,  
        Category__c, Report_Classification__c, Region__c, Comments__c, Status_Update__c, 
        Last_Update__c 
        FROM Account 
        WHERE Report_Classification__c = 'Existing Plant' 
        ORDER BY Region__c DESC, Logo__c, Parent.Name];
        RETURN accts;       
    }

public PageReference save() {
     UPDATE accts;
     return null;
    }     
    
}

 Visualforce Page:

<apex:page controller="plantListingClass" tabstyle="account" sidebar="false">
   <font size="6">
   Activity Report: Existing Plants
   </font>
    <BR /> <BR />      

   
   <apex:form >
 
   <apex:pageBlock >
 
   <apex:pageMessages />
   <apex:pageBlockSection title="Existing Plants"/>
   <apex:pageBlockTable value="{!accts}" var="a">
      <apex:column value="{!a.Region__c}"/> 

      <apex:column headerValue="Parent">
         <apex:outputField value="{!a.Logo__c}"/>
      </apex:column>          

      <apex:column headerValue="Company">
         <apex:outputField value="{!a.Parent.Name}"/>
      </apex:column>                 

      <apex:column headerValue="Plant">
         <apex:outputField value="{!a.Name}"/>
      </apex:column>   
            
      <apex:column headerValue="State">
         <apex:outputField value="{!a.BillingState}"/>
      </apex:column> 
            
    
      <apex:column value="{!a.Last_Update__c}"/>                 
      <apex:column headerValue="Status Update">
         <apex:inputField value="{!a.Status_Update__c}"/>
      </apex:column>
      <apex:column headerValue="Comments">
         <apex:inputField value="{!a.Comments__c}"/>
      </apex:column>
 
   </apex:pageBlockTable>
  <apex:pageBlockButtons >
      <apex:commandButton value="Save" action="{!save}"/>
      </apex:pageBlockButtons>  
   </apex:pageBlock>
   </apex:form>
Report Generated: <apex:outputText value="{!NOW()}"></apex:outputText>    
</apex:page>

 Test Class:

@isTest
private class plantListingTest {
    static testMethod void validatePlantListingClass() {
 
 
     Account testAccount = new Account(Name='Test Company Name',
                                        Category__c = 'Customer / Prospect',
                                        Report_Classification__c = 'Existing Plant',
                                        Region__c = 'West Region',
                                        Comments__c = 'Test Comments',
                                        Status_Update__c = 'Pending Bid',
                                        billingState='AZ');
     insert testAccount;
       
     testAccount.billingState='CA';
     update testAccount;

     // Verify that the billingState field was updated in the database.
     Account updatedAccount = [SELECT billingState FROM Account WHERE Id = :testAccount.Id];
     System.assertEquals('CA', updatedAccount.billingState);
        
        plantListingClass ctrl = new plantListingClass();
        
        Integer accSize = ctrl.getAccts().size();
        System.assert (accSize >= 1);
        
    
    

    }


}

 Here is my code coverage report:

 

I'm just getting started with Apex and am having a little trouble getting my first test class past 57%. The test is for a very simple custom controller for a visualforce page which returns a list of values from an SOQL query, then updates any records that are modified. The controller works fine, and I've poured over all the developer documentation and board posts I can find but still can't get the test to fly.

 

I intend to improve my Apex knowledgebase with some additional training but in the meantime really need to get this one class up and running. Any help would be greatly appreciated. My current code is below:

 

Custom Controller:

public class plantListingClass {
  
    public Account[] accts = new Account[0];

  public Account[] getAccts() {
        
        accts = [SELECT ID, Parent.Name, Name, BillingState, Logo__c,  
        Category__c, Report_Classification__c, Region__c, Comments__c, Status_Update__c, 
        Last_Update__c 
        FROM Account 
        WHERE Report_Classification__c = 'Existing Plant' 
        ORDER BY Region__c DESC, Logo__c, Parent.Name];
        RETURN accts;       
    }

public PageReference save() {
     UPDATE accts;
     return null;
    }     
    
}

 Visualforce Page:

<apex:page controller="plantListingClass" tabstyle="account" sidebar="false">
   <font size="6">
   Activity Report: Existing Plants
   </font>
    <BR /> <BR />      

   
   <apex:form >
 
   <apex:pageBlock >
 
   <apex:pageMessages />
   <apex:pageBlockSection title="Existing Plants"/>
   <apex:pageBlockTable value="{!accts}" var="a">
      <apex:column value="{!a.Region__c}"/> 

      <apex:column headerValue="Parent">
         <apex:outputField value="{!a.Logo__c}"/>
      </apex:column>          

      <apex:column headerValue="Company">
         <apex:outputField value="{!a.Parent.Name}"/>
      </apex:column>                 

      <apex:column headerValue="Plant">
         <apex:outputField value="{!a.Name}"/>
      </apex:column>   
            
      <apex:column headerValue="State">
         <apex:outputField value="{!a.BillingState}"/>
      </apex:column> 
            
    
      <apex:column value="{!a.Last_Update__c}"/>                 
      <apex:column headerValue="Status Update">
         <apex:inputField value="{!a.Status_Update__c}"/>
      </apex:column>
      <apex:column headerValue="Comments">
         <apex:inputField value="{!a.Comments__c}"/>
      </apex:column>
 
   </apex:pageBlockTable>
  <apex:pageBlockButtons >
      <apex:commandButton value="Save" action="{!save}"/>
      </apex:pageBlockButtons>  
   </apex:pageBlock>
   </apex:form>
Report Generated: <apex:outputText value="{!NOW()}"></apex:outputText>    
</apex:page>

 Test Class:

@isTest
private class plantListingTest {
    static testMethod void validatePlantListingClass() {
 
 
     Account testAccount = new Account(Name='Test Company Name',
                                        Category__c = 'Customer / Prospect',
                                        Report_Classification__c = 'Existing Plant',
                                        Region__c = 'West Region',
                                        Comments__c = 'Test Comments',
                                        Status_Update__c = 'Pending Bid',
                                        billingState='AZ');
     insert testAccount;
       
     testAccount.billingState='CA';
     update testAccount;

     // Verify that the billingState field was updated in the database.
     Account updatedAccount = [SELECT billingState FROM Account WHERE Id = :testAccount.Id];
     System.assertEquals('CA', updatedAccount.billingState);
        
        plantListingClass ctrl = new plantListingClass();
        
        Integer accSize = ctrl.getAccts().size();
        System.assert (accSize >= 1);
        
    
    

    }


}

 Here is my code coverage report: