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

Unit Testing - No idea how to do it??

Hi Can someone please help me write a test so I can deploy an APEX class.


I had to edit some previous code that someone wrote and I am try to learn APEX and Force and read some articles on testing but don't have a clue on how/ what to test in my code.  Coming from a web designer background you just test it in the browser and  it's all good.


public with sharing class EventListsStates {

    private static string prodId;
    private static string noRows;
    public EventListsStates() {
        prodId = ApexPages.currentPage().getParameters().get('prodId');
        noRows = ApexPages.currentPage().getParameters().get('noRows');
        noRows = (noRows == null || noRows == '') ? '5' : noRows; 

    public Campaign campaign {get ;set ;}

   public list<Campaign> upcommingEventsNSW {get {
        if (upcommingEventsNSW == null) {
            upcommingEventsNSW = new List<Campaign>([Select Name,Opportunity_Category__c,Event_Date__c,Venue_Name__c,Event_Month__c,Event_Day__c,Address_Details__c, StartDate, Running_Times__c, Product_Name__c, Location__c, IsActive From Campaign  where Location__c = 'Sydney' and startdate >= today and IsActive = True and Publish_on_the_web__c = true and Product_Name__c = :prodId order by startDate ASC limit :integer.valueOf(noRows)]);
        return upcommingEventsNSW;
    } set;}

 Thank you!!



Best Answer chosen by Admin (Salesforce Developers) 

Hey West,


go for this link , you will definetly ge  an idea for the test classes

All Answers


Hey West,


go for this link , you will definetly ge  an idea for the test classes

This was selected as the best answer

Hi Abhi,


Thank you for the post I passed the test using the following code. I'm not sure if it is correct but it seemed to work.  I now will try to deploy it.  Will Salesforce know that it has passed the test, will it embed that in the meta data?  Anyway here is the code that I used for the test.

    private class Test_EventListsStates { 

        static testMethod void EventListsStatesUnitTest() {
        EventListsStates controller = new EventListsStates();




Your code is just perfect ,.....yes you can deploy it.



mark that answer as correct for other peoples.

Check this out, an app that does unit testing for you.