Skip to main content
1 of 2

How to write a test method/class

I have created a simple apex class to be used in conjunction with a visualforce page. Everything is working as I had intended it to in the sandbox and I am now ready to push it over to production. The only problem is that I have no idea how or where to begin writing a test class to test my code coverage.

Here is the class that I created:

public with sharing class clsOpportunity10 {

public PageReference save() {
    update opportunities;       
    update prospects;
    update pursuits;
    update closing;
    update budgeting;
    update promised;
    return null;
}


public List<Opportunity> opportunities {get;set;}
public clsOpportunity10()
{
    opportunities = [select name, Project_Delivery_Method__c, Amount, Gross_Margin__c, Gross_Margin1__c, Probability, Probability_of_Owner_Proceeding__c, Bid_Due_Date__c, CloseDate, stagename, First_Year_Burn__c, Second_Year_Burn__c, Third_Year_Burn__c, Fourth_Year_Burn__c, Current_120_Day_List__c, Affecting_Current_Year_Book_and_Burn__c, Pathway_to_CY_Plan__c from opportunity where StageName = 'Needs Qualifying' and Branch__c = '10 - Western PA' and RecordType.Name = 'Construction' ORDER BY Probability DESC];
}

public list<Opportunity> prospects {get;set;}

{
    prospects = [select name, Project_Delivery_Method__c, Amount, Gross_Margin__c, Gross_Margin1__c, Probability, Probability_of_Owner_Proceeding__c, Bid_Due_Date__c, CloseDate, stagename, First_Year_Burn__c, Second_Year_Burn__c, Third_Year_Burn__c, Fourth_Year_Burn__c, Current_120_Day_List__c, Affecting_Current_Year_Book_and_Burn__c, Pathway_to_CY_Plan__c from opportunity where StageName = 'Selling' and Branch__c = '10 - Western PA' and RecordType.Name = 'Construction' ORDER BY Probability DESC];
}

public list<Opportunity> pursuits {get;set;}

{
    pursuits = [select name, Project_Delivery_Method__c, Amount, Gross_Margin__c, Gross_Margin1__c, Probability, Probability_of_Owner_Proceeding__c, Bid_Due_Date__c, CloseDate, stagename, First_Year_Burn__c, Second_Year_Burn__c, Third_Year_Burn__c, Fourth_Year_Burn__c, Current_120_Day_List__c, Affecting_Current_Year_Book_and_Burn__c, Pathway_to_CY_Plan__c from opportunity where StageName = 'Proposal' and Branch__c = '10 - Western PA' and RecordType.Name = 'Construction' ORDER BY Probability DESC];
}

 public list<Opportunity> closing {get;set;}

{
    closing = [select name, Project_Delivery_Method__c, Amount, Gross_Margin__c, Gross_Margin1__c, Probability, Probability_of_Owner_Proceeding__c, Bid_Due_Date__c, CloseDate, stagename, First_Year_Burn__c, Second_Year_Burn__c, Third_Year_Burn__c, Fourth_Year_Burn__c, Current_120_Day_List__c, Affecting_Current_Year_Book_and_Burn__c, Pathway_to_CY_Plan__c from opportunity where StageName = 'Closing' and Branch__c = '10 - Western PA' and RecordType.Name = 'Construction' ORDER BY Probability DESC];
}

 public list<Opportunity> budgeting {get;set;}

{
    budgeting = [select name, Project_Delivery_Method__c, Amount, Gross_Margin__c, Gross_Margin1__c, Probability, Probability_of_Owner_Proceeding__c, Bid_Due_Date__c, CloseDate, stagename, First_Year_Burn__c, Second_Year_Burn__c, Third_Year_Burn__c, Fourth_Year_Burn__c, Current_120_Day_List__c, Affecting_Current_Year_Book_and_Burn__c, Pathway_to_CY_Plan__c from opportunity where StageName = 'Budgeting' and Branch__c = '10 - Western PA' and RecordType.Name = 'Construction' ORDER BY Probability DESC];
}

 public list<Opportunity> promised {get;set;}

{
    promised = [select name, Project_Delivery_Method__c, Amount, Gross_Margin__c, Gross_Margin1__c, Probability, Probability_of_Owner_Proceeding__c, Bid_Due_Date__c, CloseDate, stagename, First_Year_Burn__c, Second_Year_Burn__c, Third_Year_Burn__c, Fourth_Year_Burn__c, Current_120_Day_List__c, Affecting_Current_Year_Book_and_Burn__c, Pathway_to_CY_Plan__c from opportunity where StageName = 'Promised' and Branch__c = '10 - Western PA' and RecordType.Name = 'Construction' ORDER BY Probability DESC];
}

}

I am new to apex (and writing code in general) so, any help would be greatly appreciated.