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
RickyPHewittRickyPHewitt 

Unit Test for VisualForce Controller

I'm having a unit test code coverage issue with the VF controller I have set up. I have looked across the web and found a few similar case's, but I'm very new to Apex/VF and just need a little more clarification.

 

The controller code will be posted as a reply to this message as I am getting a error about max characthers.

 

Any help would be greatly appreciated!

 

Thank you,

RickyPHewittRickyPHewitt
public with sharing class ServiceCloudSupportSidebarEntitlements {
  
  private List<Entitlement> entitle;
    private Contact cntact; 
    public ServiceCloudSupportSidebarEntitlements(ApexPages.StandardController controller) {
        this.cntact= (Contact)controller.getRecord();
    }
    public List<Entitlement> getEntitle()
    {
        Contact con = [Select id, Account.id FROM Contact where id = :cntact.id];
        if (con.Account == null)
         return null;

        entitle = [Select id, Name, Account.Name, Type from Entitlement where Account.id = :con.Account.id];
        
        if(entitle == null)
         return null;
        
        return entitle;
    }

  public ServiceCloudSupportSidebarEntitlements() {}
  
  public static testMethod void testSCSSE() 
  {
    
    //set the current page since it is a visualforce page
    PageReference pg = Page.Console_top_bar_contact;
    Test.setCurrentPage(pg);
    
    //Set up contact:
    Account myAccount = new Account(Name = 'aNewAccount');
    insert myAccount;
    
    Contact myContact = new Contact(AccountId = myAccount.ID, lastname = 'Bob', firstname = 'Billy');
    insert myContact;
    
    Entitlement myEntitlement = new Entitlement(Name = 'aNewEntitlement', Contract_Type__c = 'Paying');
    myEntitlement.AccountId = myAccount.Id;
    insert myEntitlement;
    
    //Set Test Params
    ApexPages.currentPage().getParameters().put('id', myContact.Id);
    
    Test.startTest();
    //instantiate a new class
    ServiceCloudSupportSidebarEntitlements SCSSE = new ServiceCloudSupportSidebarEntitlements();
    List<Entitlement> getEntitle;
    Test.stopTest();
    
    
    
    
    //make assertions
    //System.assertEquals(1, entitlements.size());
  
  
  }
    
    
      
    

}