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

Salesforce Calendar, Google Calendar, or PHP Calendar

I have a custom object called "Maintenance Window", which includes a start date/time and end date/time for the event.  Typically these are 1-6 hour long events, but the often cross the midnight boundary.  My current project is to map these events on to a calendar -- so that a user can see all the upcoming (or historic) maintenance windows on a monthly calendar, at a glance.  The Maintenance Window detail records and Calendar need to stay in synch, so that if the start or end date/time fields on the Maintenance Window are updated, the calender will be updated to reflect this information, as well.
I've yet to decide where I'm going to map these events -- either to a public calendar in SFDC, a group calendar in Google, or a PHP calendar.  I'm leaning toward the latter, I think.  We're already copying the data over manually to a PHP calendar (it's this manual copy / data duplication that I'm looking to eliminate), and I really like the visual appearance of the PHP calendar (and the ability to control the font colors and details in the PHP Calendar). 
Still, as much as I like the PHP calendar, my preference is to keep everything in one tool -- SFDC.  Less databases / servers to maintain, yeah? 
Have any of you done something like this?  Which of these options (or something completely different) did you go with, and why?  What were your biggest pitfalls and "if I had to do it all again, I would have ..."

I had an epiphany yesterday on this.  Why use the Salesforce Calendar, Google Calendar or a PHP Calendar at all?  All of those are just graphical represenations of data in a database.  I already have the data in a database.  It's stored as detail records in a custom object, which include custom fields for scheduled start date/time and scheduled end date/time. 

I just need to display this data in something that looks like a calendar.  I can do that in Visualforce page as a table!

It would be neat if there was already a page controller or a template for a "daily planner" or calendar (or both).  Anyone have a VF calendar-like page up their sleeve?


I have a need much like you have described here for a session calendar that allows viewing of session dates from a custom object. I too started out with a standard SF calendar but ran into the API issues. I do like the idea of the calendar based on a VF page . Can you tell me more about how you have made out with this? I would like to create my calendar and perhaps share it among users via Google Apps.


I ended up making the Calendar in VisualForce.  After my last post, I searched around the developer forums, and found a great post from Ron Hess:
I took most of Ron's code, and tweaked it for my custom object.  My final creation is here:

Thanks JP, that looks like it is just what I am looking for! I do appreciate your quick response and your help.

Don Waters

I attempted to use this myself, and when creating the Class, I get an error message when saving along the lines month.week does not exist. I thought creating the class is the first step, but I must have missed something.
Post your code source and the exact error message, and I'll see what I can help with.
I went my developer account, then to setup> develop> apex classes> new and paste:
public class repeatCon {

public void next() {

public void prev() {

public repeatCon() {

Date d =; // default to today
Integer mo = d.month();
String m_param = System.currentPageReference().getParameters().get('mo');
String y_param = System.currentPageReference().getParameters().get('yr');

// allow a month to be passed in on the url as mo=10
if (m_param != null) {
Integer mi = Integer.valueOf(m_param);
if (mi > 0 && mi <= 12) {
d = Date.newInstance(d.year(),mi,;
// and year as yr=2008
if (y_param != null) {
Integer yr = Integer.valueOf(y_param);
d = Date.newInstance(yr, d.month(),;


public List<Month.Week> getWeeks() {
system.assert(month!=null,'month is null');
return month.getWeeks();

public Month getMonth() { return month; }

private void setMonth(Date d) {
month = new Month(d);
system.assert(month != null);

Date[] da = month.getValidDateRange(); // gather events that fall in this month
events = [ select id,subject,description,activitydate,activitydatetime,DurationInMinutes
from Event
where activitydate >= :da[0] AND activityDate <= :da[1]
order by activitydatetime];

month.setEvents(events); // merge those events into the month class

private void addMonth(Integer val) {
Date d = month.getFirstDate();
d = d.addMonths(val);

private List<Event> events;
private Month month;
My error message is: "Error: Compile Error: Invalid type: Month.Week at line 34 column 13
On the post you linked, there is a second Apex class.  You need to have both.

Review the code in the 2nd Apex Class called "public class Month".  Add it the same way you did the "public class repeatCon" class.

A warning -- you're still going to have issues.  The code is not complete yet.  The sample code shows how to create a List of Lists.  You'll still need to do some code mods to get this running.  If I recall, I just commented out a line in the setEvents method, because it referenced an object that wasn't known to my instance "EventItem".

That should allow it to run normally.
Ok, so first question. I have enterprise edition, and might not have access to use custom apex classes in my production account. Is this a problem?

If not, can you be more specific on where what code goes where?
Apex is supported fully in Enterprise Edition.

I implemented the code through our organization's sandbox, then deployed it into production using the Eclipse IDE.

I'm afraid it wouldn't be terribly useful for me to post the modified code I used to create the calendar picture above.  The information displayed is for a custom object, which has some complex junctor object relationships underneath it.  I'm afraid my Apex code would make readers dizzy (at least, it has that affect on me), and wouldn't be terribly helpful as a tutorial on building the app.

I think you're better off taking the links to Ron Hess's calendar sample source


Use that as the frame work for your Visualforce page and apex classes (you'll be creating two classes, he provides the source in the link above).  Ron's code was sample source only, it wasn't intended to run on it's own.  You will get a save error when you try to save one of the classes (I think it was the "Month" class), but you should be able to figure out the error and comment out the offending code, just to see what his calendar applet looked like.

If that's beyond your Apex / VF coding level right now, I'd start learning more about these tools here: