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
Matt TindallMatt Tindall 

Test Class

I've tried every tutorial and referencing website I can and still just cannot figure what I need to do or how to start a test class for the following class. Please is there anyone out there who can help get me started?

public with sharing class Staff_Holiday_Calculator{
    // Staff Variables
        Private integer staff_allowance=252;
        public integer staff_total_used;
        public List<Holiday__c> staff_holidays {get;set;}
    
    // The SOQL without the order and limit
        private String soql {get;set;}
        
    // The current sort direction. Default to asc
        public String sortDir {
                get { if (sortDir == null) {sortDir = 'asc'; } return sortDir; }
                set;
        }
    
    // Sort the data by the Postcode
        public String sortField {
            get  { if (sortField == null) {sortField = 'Leave_Work__c'; } return sortField;  }
            set;
        }
    
    // format the soql for display on the visualforce page
        public String debugSoql {
            get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }
            set;
        }
    
    // init the controller and display some sample data when the page loads
        public Staff_Holiday_Calculator() {
            soql = 'SELECT Staff_Memeber__c, Leave_Work__c, Return_to_Work__c, Hours_Used__c, Reason__c, Status__c FROM Holiday__c WHERE Staff_Memeber__c=';
            runQuery();
            
        List<AggregateResult> results=[select sum (Hours_Used__c) FROM Holiday__c WHERE Staff_Memeber__c = 'staff'];
        decimal staff_temp = (decimal)results[0].get('expr0');
        staff_total_used = staff_temp.intvalue();
                    
        }
    
        // toggles the sorting of query from asc<-->desc
                public void toggleSort() {
                // simply toggle the direction
                        sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
                // run the query again
                        runQuery();
                }
 
        // runs the actual query
                public void runQuery() {
                    try {
                        staff_holidays = Database.query(soql + '\'staff\'' + ' order by ' + sortField + ' ' + sortDir + ' limit 100');
                    } catch (Exception e) {
                        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!'));
                    }
                }
                
        // The number of hours a staff member is allowed 
            Public Integer getstaff_allowance() {
                return staff_allowance;
            }
    
        // The total numer or hours already used.
            Public Integer getstaff_total_used() {
                return staff_total_used;
            }
            
        // The total number of of hours allowed minus the total number of hours used.
            Public Integer getstaff_Available() {
                return staff_allowance-staff_total_used;
            }
            
        // A working day is based on 9 hours. Divide the available hours by 9 to show the number of whole days available.
            public integer getstaff_Daysleft() { 
                return (staff_allowance-staff_total_used)/9;   
            }
}

 

Abhi_TripathiAbhi_Tripathi

Hey Matt,

 

Go for this link, it will surely help you

 

http://abhithetechknight.blogspot.in/2013/10/salesforce-test-class-basics.html