I have a visualforce page with a drag and drop calendar based on: https://salesforceprojects.quora.com/Implement-full-calendar-drag-and-drop-in-Visualforce-page

I have started to write my test classes. The values of two strings are set on the visualforce page in apex: param Values. When running my test these values are returning null. I thought I could mimic this in my test class by using a getParamerters().put() in my test class, however when running my test these are still being passed into the method as null?

I am having trouble testing the setEvent method in the Extension:

public class CalendarControllerExtension {

    private final SalesActivityPlan__c sap; 
    public list <CalendarEvent> events {get;set;}    

    // As Events can be dynamically dragged around the calender variables are used for these selections
    public String eventIdTemp   {get;set;}  //Selected event Id coming from vf page
    public String st    {get;set;}  //Selected event start date & time
    public String ed    {get;set;} //Selected event end date & time
    public List <Event> eventList = new List <Event> ();

    //Do some stuff

//   Parse the date format and set values when an event is dragged around the calendar
    public void setEvent() {
        if (ed != null & st !=null){
        List <String> stringParts = ed.split('T');
        List <String> dateParts = stringParts[0].split('-');
        List <String> timeParts = stringParts[1].split(':');  
        DateTime dt1 = DateTime.newInstance(Integer.valueOf(dateParts[0]), Integer.valueOf(dateParts[1]), Integer.valueOf(dateParts[2]), Integer.valueOf(timeParts[0]), Integer.valueOf(timeParts[1]), Integer.valueOf(timeParts[2]));
        stringParts = st.split('T');
        dateParts = stringParts[0].split('-');
        timeParts = stringParts[1].split(':');
        DateTime dt2 =  DateTime.newInstance(Integer.valueOf(dateParts[0]), Integer.valueOf(dateParts[1]), Integer.valueOf(dateParts[2]), Integer.valueOf(timeParts[0]), Integer.valueOf(timeParts[1]), Integer.valueOf(timeParts[2]));
        for(Event e : eventList) {  
            if(e.Id == eventIdTemp) { 
                e.EndDateTime = dt1;
                e.StartDateTime = dt2;
                update e; }

Test Class:


public class ActivityPlanExtensionTest {


static void TestActivityPlanExtension(){

    User u3 = [SELECT Id FROM User WHERE Email='[email protected]'];

    Event TestEvent = new Event(Subject = 'Test', ActivityDate=date.today(), StartDateTime=datetime.now(), EndDateTime=datetime.now());
    insert testevent;

    String ed = string.valueOfGmt(testevent.enddatetime);
    String st = string.valueOfGmt(testevent.startdatetime);
    String eventIdTemp = string.valueof(testevent.id);

    SalesActivityPlan__c testplan = new SalesActivityPlan__c();

    //Instantiate VF Page
    PageReference pg = Page.ActivityPlan;   
    ApexPages.currentPage().getParameters().put('st', string.valueOfGmt(testevent.startdatetime));
    ApexPages.currentPage().getParameters().put('ed', string.valueOfGmt(testevent.enddatetime));

    // Instantiate the controller extensions and run the methods
    ApexPages.StandardController sc = new ApexPages.standardController(testplan);   
    ActivityPlanExtension actplan = new ActivityPlanExtension(sc);
    CalendarControllerExtension calendarplan = new  CalendarControllerExtension(sc);
        st = ApexPages.CurrentPage().GetParameters().Get('st');
        ed = ApexPages.CurrentPage().GetParameters().Get('ed');

  • These comments in your code are excessive and make it much harder to read.
    – Adrian Larson
    Commented Apr 10, 2017 at 18:06
  • 1
    Can you try like this : calendarplan.st = string.valueOfGmt(testevent.startdatetime); ?
    – javanoob
    Commented Apr 10, 2017 at 18:16
  • 1
    I've taken out a good portion of the code. Hopefully it is more readable. Commented Apr 10, 2017 at 18:23
  • 2
    Did you mean to set calendarplan.st and calnedarplan.ed instead of st and ed? You'll have a much easier time working with this code if you work on sensible naming (for instance name your extension instance extension and your mental paradigm will be easier to grasp as you code).
    – Adrian Larson
    Commented Apr 10, 2017 at 18:31
  • 2
    I don't see anywhere in your controller where you are "getting" the page parameters so what's the point? Just set st and ed directly
    – Eric
    Commented Apr 10, 2017 at 18:53

1 Answer 1


Credit to javanoob, Adrian Larson and Eric.

set calendarplan.st and calnedarplan.ed works perfectly.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .