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
Vigneshwaran LoganathanVigneshwaran Loganathan 

Importing Calendar


I am trying to add calender to My Dev Org with the help of one link. 

But Im facing issue on Pageload funtion,
public class CalendarExample_Controller {

    public Boolean includeMyEvents {get;set;}

    public list<calEvent> events {get;set;}


    //The calendar plugin is expecting dates is a certain format. We can use this string to get it formated correctly

    String dtFormat = 'EEE, d MMM yyyy HH:mm:ss z';



    public CalendarExample_Controller() {

        //Default showing my events to on

        includeMyEvents = true;



    public PageReference pageLoad() {

        events = new list<calEvent>();

        //Get Contact's Birthdays

        for(Contact cont : [select Id, Birthdate, FirstName, LastName from Contact where Birthdate != null]){

            //here we need to replace the birth year with the current year so that it will show up on this years calendar

            DateTime startDT = datetime.newInstance(Date.Today().Year(),cont.Birthdate.Month(), cont.Birthdate.Day());

            calEvent bday = new calEvent();


            bday.title = cont.FirstName + ' ' + cont.LastName + '\'s Birthday!';

            bday.allDay = true;

            bday.startString = startDT.format(dtFormat);

            //Because this is an all day event that only spans one day, we can leave the send date null

            bday.endString = '';

            bday.url = '/' + cont.Id;

            bday.className = 'event-birthday';



        //Get Campaigns

          for(Campaign camp : [select Id, Name, StartDate, EndDate from Campaign where IsActive = true])

         DateTime startDT = camp.StartDate;
            DateTime endDT = camp.EndDate;

            calEvent campEvent = new calEvent();            

            campEvent.title = camp.Name;

            campEvent.allDay = true;

           campEvent.startString = startDT.format(dtFormat);

          campEvent.endString = endDT.format(dtFormat);

            campEvent.url = '/' + camp.Id;

            campEvent.className = 'event-campaign';

        return null;



    public PageReference toggleMyEvents() {


            includeMyEvents = false;



            includeMyEvents = true;



        return null;



    //Class to hold calendar event data

    public class calEvent{

        public String title {get;set;}

        public Boolean allDay {get;set;}

        public String startString {get;private set;}

        public String endString {get;private set;}

        public String url {get;set;}

        public String className {get;set;}



Its showing "Attempt to de-reference a null object" on campEvent.endString . But from Debud Log i can see records. 

What could be the reason for this? 

SandhyaSandhya (Salesforce Developers) 
Try to print 

before this line

campEvent.endString = endDT.format(dtFormat); 
And also try in a different browser and see.

Hope this helps you!

Thanks and Regards