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
Steve LoudermilkSteve Loudermilk 

Help with get,set controller Test Class

Hello everyone,

I am new to working with visualforce controllers and need a little help with a test class.

This is my code which is fairly simple, just not sure how to work with as far as getting code coverage.

public class CraneTicketID {
    public Daily_Crane_Ticket__c currentrecord {get; set;}
    
   
    public CraneTicketID(ApexPages.StandardController controller) {
        currentRecord = [SELECT Id  FROM Daily_Crane_Ticket__c WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
    }

}

Any help is appreciated.
Best Answer chosen by Steve Loudermilk
DeveloperSudDeveloperSud

All Answers

DeveloperSudDeveloperSud
This was selected as the best answer
Steve LoudermilkSteve Loudermilk
@isTest 
public class ExtensionTestClass 
{
 static testMethod void testMethod1() 
 {
 Daily_Crane_Ticket__c testdct = new Daily_Crane_Ticket__c();
     testdct.Date__c=System.today() ;
     testdct.Job_Number__c='00001';
     insert testdct;

 Test.StartTest(); 
  ApexPages.StandardController sc = new ApexPages.StandardController(testdct);
  CraneTicketID ctid = new CraneTicketID(sc);

  PageReference pageRef = Page.SignOff_v2; // Add your VF page Name here
  pageRef.getParameters().put('id', String.valueOf(testdct.Id));
  Test.setCurrentPage(pageRef);

  ctid.save(); 
//call all your function here 
//error is appearing here method does not exist or incorrect signature
 Test.StopTest();
 }
}

I think I'm in the right ballpark, not exactly sure what's missing
DeveloperSudDeveloperSud
Hi Steve,

Did you create the save method in your extension class? if not it will show an error like this .
Steve LoudermilkSteve Loudermilk
got it! thanks!