Integrating Salesforce with Google Drive in 3 easy steps
Accessing Google Drive files… Step by step. 🚀
Those 3 easy steps are ⚙️:
- Making Google Drive ready for Integration
- Making Salesforce ready for Integration
- & finally, let’s connect the dots…
Making Google Drive Ready for Integration
Creating a Project in the Google Developers Console
- First, you need an existing Google account. If not sign up here.
- Then login with Google credentials to your Google App for Work admin account: https://console.cloud.google.com/
3. Create New Project, give it a name let's say Salesforce Integration, Save it and finally Select the newly created project.
4. From the project dashboard, click the Menu icon in the upper left, and then click APIs and Services. Then, Enable APIs and Services, and search for Google Drive API. Select it and click Enable API on Google Drive API
Preparing for Google Drive Credentials
- Now, click Credentials in the menu on the left side.
- In the OAuth Consent Screen tab, enter a valid email address and application name, and click Save. Make sure to Publish the app, so that publication status becomes In production for the record.
3. In the Credentials tab, click on Create Credentials, select OAuth Client Id
4. Select Application type as a Web application, give it a name, e.g. SalesforceGoogleDriveClient and Create.
5. Copy the client Id and client secret which gets created in the above step and save it in a text file. Optionally, you can download and save the JSON file which gets created for later usage.
Imporatant:
The client Id and client secret created in the above step would be used in the upcoming step which creates an auth. provider in Salesforce for Google drive.
Making Salesforce Ready for Integration 👀
Creating an Auth. Provider in Salesforce
- From Setup > search for Auth. Providers in the Quick Find box and then select Auth. Providers. Click New to create a fresh record.
- For Provider Type, select Open ID Connect
3. Now, for the new Auth. Providers fill in the below details as mentioned:
- Name — Enter the name you want to appear in Salesforce: ‘Google Drive Provider’
- URL Suffix — Enter the suffix at the end of the URL path: ‘GoogleDriveProvider’
- Consumer Key — client ID you copied when creating the Google project.
- Consumer Secret — client secret you copied when creating the Google project.
- Authorize Endpoint URL — Enter ‘https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=force’
- Token Endpoint URL — Enter ‘https://accounts.google.com/o/oauth2/token’
- Default Scopes — Enter ‘openid email profile https://www.googleapis.com/auth/drive’
Once all details are entered, Save the record. It should look something like the below:
4. Note down the Callback URL value from the newly created record. This URL value would be used while editing the Google project created in the earlier steps.
https://sombirsheoran-dev-ed.my.salesforce.com/services/authcallback/GoogleDriveProvider
Editing Google Drive Project with Callback URL
- Go again to our Google Drive API Manager page, in the left side of the menu, click Credentials
- Click to open the previously created web app: SalesforceGoogleDriveClient
- In the Authorised redirect URIs section of the page, click Add URI to add the Callback URL while creating the Auth. Providers in Salesforce:
4. Enter Authorised redirect URIs = Callback URL value and save it.
Now the initial setup is ready from the Google Drive and Salesforce perspectives.
& Finally, Let’s connect the dots…
Define an External Data Source for Google Drive
- From Setup > search for External Data Sources: Select ‘External Data Sources’ and create a new record.
- Give it a meaningful name and select Files Connect: Google Drive for the Type field.
- For Identity Type, select Per user and OAuth 2.0 for the Authentication protocol.
- For the Authentication Provider, select the GoogleDriveProvider record created in earlier steps.
- Leave Scope as Blank.
- Select Start Authentication Flow on Save as True to immediately test the settings above. The final result should look as below:
7. On Save, it will launch Google authenticator to select your Google account to proceed.
Important:
You might get errors like below in case your web app in not published
8. Click Go to salesforce.com (unsafe) to verify the app and proceed
9. In the next step, select all required permissions, as mentioned in the scope, and click continue.
10. Finally, you’re routed back to External Data Source: Google Drive. It should show status as Authorized. Click on Validate and Sync, select Sync in the background, and wait until Status moves from RUNNING to COMPLETE. It creates a new External object: items_Google_Drive
10. Create a new permission set FilesConnect Permission Set as mentioned in the blog and make sure the following permissions are added and assigned to required users.
Files Connect Cloud: Access cloud-based external content sources, such as SharePoint Online: This is a system permission
Now we need to add newly created Custom Object (External) and External Data Source to the already created permission set: FilesConnect Permission Set : items_Google_Drive
11. Optionally, you can create a new tab with the new object items_Google_Drive so that can be launched to verify the data.
Verifying success: 🧪Test Google Drive connection
- In Salesforce lightning, go to the Files tab and make sure you’ve Google Drive as a connected source to access its files. Select any random file to perform a valid operation.
2. In Salesforce classic, go to any Salesforce object, under Feeds > Files > Select a file from Salesforce:
3. Then you see Google Drive and all its related files. Select any random file to perform a valid operation.
4. Moreover, you may launch the new tab created using the new external object items_Google_Drive in one of the earlier steps and see all the records to verify the Google drive data in Salesforce.
Congratulations, it confirms that Salesforce to Google Drive integration is working perfectly.❤️
References:
https://help.salesforce.com/s/articleView?id=sf.admin_files_connect_google_auth.htm&type=5
Developer details:
- Twitter: @sombirsheoran
- LinkedIn : https://www.linkedin.com/in/sombirsheoran
Please reach out to me for any suggestions or feedback. Would love to hear them ❤ If you loved this post, please applaud me at the end of this post with a 👏