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
Richard ZenkevichRichard Zenkevich 

Lightning sync with Google calendar for events generated by apex code

Hello everyone,
I just had set up Lightning Sync (with Google Calendar) and it works pretty well with events manually created by user. But it refuse to synchronize events created from apex code.

For example if I create new event from anonimous apex, or process builder for some user – it will appear in his calendar on Salesforce org, but it would not be synchronized with users Google calendar.
But if user select this new event, click edit and then save (even without changes) – this event will be synchronized just us other manually created events.

Lightning Sync Error Report doesn't show any errors (events created by user sunc just fine).

Any ideas how to sync "syntetic" events?
NagendraNagendra (Salesforce Developers) 
Hi Richard,

Why events created though Apex code doesn't sync to Google Calendar using Lightning sync because its designed in such a way that when such events either created or edited from LEX/S1 the only sync.
to have LEX Only common functionality enforced, so such events will show if they have been created/edited from LEX/S1 or not and based on that check it gets synced.

Thanks,
Nagendra
Richard ZenkevichRichard Zenkevich
Hello againg,

I wasn't able to solve this so we decided to make it work another way - save event on Google side (usin Google Calendar API) and then let it sync to Salesforce. In our case it's ok to make it work that way.

Unfortunatelly Google has no ready-to-use implementation of Google API integration for Apex so I developed one for our usecase but now it works.
G FudalaG Fudala
Hi Richard,
Would you be willing to share the Apex Google API you created? I suspect a lot of people will need to work around this Lightning Sync limitation (including me). :)

 
Richard ZenkevichRichard Zenkevich

Hi, G Fudala,

I'm sorry, it's not my intellectual property so I can't share it now but you can follow my steps and get the same results.

Here is useful a talk where was made something similar (but with Google Sheets): https://www.salesforce.com/video/1758915/;
and here are some repositories from this tallk: https://github.com/jpescador/google-force and https://github.com/jpescador/google-force-demo .

But there is an issue with this demo (from repositories above) - they manually share the Google Sheet table to email from Google API token file, it was not an option in my case. To make it work for all of employees from your G Suit you need to get OAuth2 session token for your admin account and you are good to go (because G Suit admin has access to all of the calendars), so no need to share all the calendars to some service email.
Read this for more info: https://developers.google.com/identity/protocols/OAuth2ServiceAccount

G FudalaG Fudala
Understandable... thank you for the links! I had done all the legwork up to G Suite authentication, I just wasn't looking forward to creating a class lib to interact with the API, especially when it already exists for so many languages more mainstream than Apex. :) Cheers!