Sync Custom Calendar with Google Calendar in Salesforce
My name is Tejbir Singh. I am senior salesforce developer having 6 years of experience. I have expertise in sales cloud, community cloud and integration of salesforce with external systems.
This blog will explain the creation of a custom calendar using the fullcalendar library and how to sync it with Google calendar in salesforce.
Follow the below steps to implement a custom calendar in salesforce:
1. Store fullcalendar.js, fullcalendar.css, moment.js, and jQuery in the static resource. These files can be found here.
2. Include fullcalendar.js, fullcalendar.css, moment.js, and jQuery into the lightning component.
3. Include the below div inside the lightning component.
4. Initialize the fullcalendar after scripts load.
Once the above steps are implemented, the calendar will be visible as shown below:
Now the second important step is to get the google calendar events and show them in the calendar. Follow the below steps for a successful connection between Salesforce and Google Calendar:
1. Create a new project in Google API Console.
2. Complete the registration for the app using the OAuth consent screen.
3. Create credentials using OAuth client ID.
4. Add the Application type and redirect URI. Authorization code will be appended at the end of redirect URI. Create a lightning app for redirect URI.
5. Once the OAuth client is created, store the Client Id and Client Secret in custom metadata type.
6. Now, make an HTTP callout to google authentication URL for granting access to Google Calendar.
7. Once permission is granted, it will get redirected to ‘redirect URI’ with auth code appended at the end of it.
8. Make an HTTP callout using auth code, client_id, and client_secret to fetch the access token, and store the access token & refresh the token in custom settings.
9. Now use the access token to fetch the calendar events and show those events in the custom calendar in salesforce.
In response, google calendar API will send all the calendar events. Parse the response and show them in the calendar in salesforce. Similarly, events can be created in google calendar from salesforce.
After implementing above steps, google calendar events will be shown in calendar in salesforce.