Hello friends, In this post, I will show you how you can integrate Salesforce with Google Calendar so that Salesforce user could aware of all upcoming events and tasks!

Below is the list of all the tasks that we will do in this post to do Integrate Google Calendar with Salesforce.

  1. Create a public List type Custom SettingGoogleCalenderInfo” to store the access/refresh token and expiry time (in Seconds).
  2. Enable Google Calendar API and create an App to get the Consumer Key and Consumer Secret
  3. Create VF page Apex Class to make the callout and store Access/Refresh Token into Custom Setting.
  4. Create Another VF page which will fetch all the List of Calendar Available into your Calendar and create a new Calendar From Salesforce.

Create New Custom Setting: –

Login into Your Salesforce Org and go to Setup -> Develop -> Custom Settings -> New

See below image for the field names and data types

Custom Setting

Create Required VF pages and Apex Classes: –

  • Open Developer Console and Create 2 Apex Classes GoogleCalenderApi and GoogleCalendarActionsController.
  • Now, Create 2 VF pages “GoogleCalendarActions” and “GoogleCalenderoAuth”
  • You will get the Complete code for All the pages and Apec Classes From Here copy the code and paste in your pages/classes.

Do Enable Google Calendar API and Settings: –

Go to  Using OAuth 2.0 to Access Google APIs and you will get Detailed Information about authentication process.

Go to Google API Console, Credentials -> Create Credentials -> oAuth Client Id


Application Type -> WEB

Authorized redirect URIs -> URL To Your VF page “You already have created the VF page if not follow the above steps and create both the pages with classes”

Open “GoogleCalenderoAuth” VF page, Click Preview and Copy the URL that URL is the Redirect URI paste that URL here.

Note: – You also need to replace “redirect_uri” variable in GoogleCalendarAPI class with your VF page URL. 

VF PAGE Preview.png

Now, Click Create, a Pop up with Client Id and Client Secret will open



Copy both Client Id and Client Secret in any text Editor like notepad++, notepad, or any editor.

Now, Open GoogleCalenderApi class replace consumerKey with your Client Id and clientSecret with your Client Secret.

Now, as we have done all the necessary steps and it’s show time.

Open “GoogleCalenderoAuth” VF page, preview it Page will look like below

VF page.png

Click “Connect With Calendar” you will be redirected to Gmail Login, Login with your Gmail, Grant Access to Application. You will get back to the same Page and Now Click “Get Access Token” a new Page “GoogleCalendarActions” will open.

VF page.png

VF page

First, we will create a New Calendar, Enter “Testing Google API ” and then Create New Calendar. You will get a Success Message with the response.

Create New Calendar

Now, List All Calendars will list all the calendars that are available to your Account.

List All Calendars.png

Note: – Using the Above Code of “GoogleCalenderoAuth” Page and “GoogleCalenderApi” Apex Class you can integrate with Any Google API. You only need to make a minor change which is the value of the calendar_Scope variable in GoogleCalenderApi class, use the scope of the API that you want to Connect. You will get the scope of all the APIs OAuth 2.0 Scopes for Google APIs.

Any Queries come in the comment section.


Please do like and share the same as sharing is caring 🙂



Our Score
Click to rate this post!
[Total: 1 Average: 5]

Leave a Reply