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
ShmeeShmee 

Updating Google Calendar when an Object Record is Created

I have created a custom object called Service_Orders__c

 

The object contains data that I would like to automatically post to my google calendar.

 

When we create the record I would like it to update the google calendar.

 

 

I have been searching for hours to see if this has been addressed somewhere but I can't seem to find a discussion on it.

 

 

 

I figure that the following process would work.

 

 

1) Create an apex class that would retrieves an Authentication Token from Google. (I have seen the example of how to do this in a visualsource page but haven't done it in a apex class)

 

2) Use and apex trigger to get the token and use it to create a calendar even "after insert"

 

 

 

I am still really new to programming and the force.com platform so any ideas or direction would help.

 

Thanks

 

Brett

 

 

 

ForcecodeForcecode

Have you already seen the Google Calendar API project and the Google Data API Toolkit ?

http://wiki.developerforce.com/index.php/Google_Calendar_API

 

http://wiki.developerforce.com/index.php/Google_Data_APIs_Toolkit_Setup

 

I decided not to do this in a trigger, because you have to use the @future statment for the function that makes the callout to Google and inserts the data into the Google Calendar. Inside the trigger the function has to be @future, in a Visualforce page this is not required.

 

You cannot pass a List to this type of functions, only primitive data types. If you have more than one date, this will not work or you have to query for the data again in this function.

 

 

ShmeeShmee

Here is what I have done so far

 

1) uploaded all the Google Data Classes via Eclipse SVN (ie.. setup the toolkit)

 

2) created the subAuth visualforce page (per http://wiki.developerforce.com/index.php/Google_Data_Authentication) which is the method for retrieving a one-time-use-token.

 

3) created the AuthSubController class to parse the url and get the token, exchange for session token, and to store sessionid's

 

4) created the googSession__c object to store session IDs

 

 

5) created apex class called updateCalendar as follows:  (this is per the Calendar API)

 

 

public class updateCalendar { CalendarService service = new CalendarService(); service.setAuthSubToken(sessionAuthToken); public static void createcalendarEvent() { GoogleData.Calendar cal = service.getCalendarByTitle('MyCalendar'); event newEvent = new Event( subject = 'Tennis with Beth', description = 'Meet for a quick lesson.', ActivityDateTime = system.now(), DurationInMinutes = 60 ); xmldom.element entry = service.insertEvent( cal, newEvent ); entry.dumpAll(); } }

 

 

 

 

 

 

So what I don't know is how to connecting all the pieces.

 

 

When I am in my custom object Service_Orders__c and I created a new record it seems like the following would need to happen:

 

1) Get a Single Use Token

2) Convert Token to Session Token

3) Store the Token in the googSession__c object

4) Connect to the calendar using the saved session token

5) Update the calendar with a New Calendar Event.

 

 

But I am not sure how to do this.

 

Thanks for your help.

ForcecodeForcecode

I have not used a token yet, my code looks like this:

@Future(callout=true) public static void addGoogleEvents(ID myObjectID) { CalendarService calsvc = new CalendarService(); calsvc.useClientLogin('myusername','mypassword'); GoogleData.Calendar cal = calsvc.getCalendarByTitle('MyCalendarName'); xmldom.element entry = calsvc.insertEvents(cal, [Select e.Subject, e.DurationInMinutes, e.Description, e.ActivityDateTime From Event e where WhatId = :myObjectID]); entry.dumpAll(); }

 

The code selects all events for the object myObjectID and adds them to the calendar.

 

Message Edited by Forcecode on 09-25-2009 09:04 AM
ShmeeShmee
how are you specifically executing this code?
ShmeeShmee

I am sorry I am such an noob on this.

I would just like to create a calendar event when an object record is created.

 

 

I need to Trigger Code

and the Apex Class code

 

 

assuming that all the Google Data API classes are installed.

 

If anyone can help I would really appreciate it.  I have spent all freakin day trying to figure this out.

 

Thanks

 

 

Brett

megha.arora1.2864414976037085Emegha.arora1.2864414976037085E

Hi,

 

I am also trying to sync salesforce with google calender.

 

Did you get any success in it so far?

 

Please share.

 

Thanks in advance!!