Back to insights
Salesforce IntegrationSalesforceGoogle Drive

Salesforce to Google Drive Integration

Integrate Salesforce with Google Drive to automatically upload, organize, and manage files using APIs and secure authentication.

Nambi Selvi10 min read

Salesforce Developer

Salesforce to Google Drive Integration cover infographic

Abstract

Organizations often store business documents such as contracts, proposals, invoices, and customer-related files in Google Drive. However, users frequently switch between Salesforce and Google Drive to access these files, reducing productivity.

This solution demonstrates how to integrate Google Drive with Salesforce using OAuth 2.0, Google Drive API, and Salesforce Named Credentials. The integration enables users to access, upload, and manage Google Drive files directly from Salesforce records while maintaining security and centralized document management.

Solution

The integration establishes secure communication between Salesforce and Google Drive using Google's OAuth 2.0 authentication mechanism.

Business Requirements

  • Access Google Drive files from Salesforce.
  • Upload files from Salesforce to Google Drive.
  • Create folders automatically in Google Drive for Salesforce records.
  • Store Google Drive file URLs in Salesforce.
  • Reduce Salesforce file storage consumption.
  • Improve document management and collaboration.

Architecture

Salesforce to Google Drive Integration Step 1Salesforce to Google Drive Integration Step 2

Components:

  • Salesforce
  • Google Cloud Platform
  • Google Drive API
  • OAuth 2.0 Authentication
  • Salesforce Named Credential
  • Apex Classes / Flow Automation

Integration Flow

  1. User uploads a file in Salesforce.
  2. Salesforce calls Google Drive API.
  3. OAuth token is used for authentication.
  4. File is uploaded to Google Drive.
  5. Google Drive returns File ID and URL.
  6. Salesforce stores the URL on the related record.

Step-by-Step Guide

Step 1: Create a Project in Google Cloud Platform

Before connecting Salesforce with Google Drive, you must create a project in Google Cloud Platform (GCP). This project will be used to manage APIs, authentication settings, permissions, and other Google services required for the integration.

Procedure

  1. Open Google Cloud Console: https://console.cloud.google.com
  2. Sign in using your Google account.
  3. From the navigation menu, select: IAM & Admin → Create Project.
  4. Enter a meaningful project name.
  5. Click Create.

Once the project is created, it will act as the central location for managing Google Drive API configurations and OAuth credentials.

Salesforce to Google Drive Integration Step 3

Step 2: Generate OAuth Credentials

Salesforce requires secure authentication to access Google Drive resources. This is achieved through OAuth 2.0 credentials.

Salesforce to Google Drive Integration Step 4

Procedure

  1. Navigate to: APIs & Services → Credentials.
  2. Select Create Credentials.
  3. Choose OAuth Client ID.
  4. Provide a suitable name for the credential.
  5. Configure the following URLs based on your application type:
    • Authorized JavaScript Origins — used for browser-based applications. Example: https://yourdomain.my.salesforce.com
    • Authorized Redirect URIs — used for handling OAuth responses. Example: https://yourdomain.my.salesforce.com/services/authcallback/GoogleDrive
  6. Click Create.

Google generates a Client ID and Client Secret. Store these values securely as they will be required during Salesforce configuration.

Salesforce to Google Drive Integration Step 5

Step 3: Enable Google Drive API

The Google Drive API must be activated before Salesforce can communicate with Google Drive.

Procedure

  1. Navigate to: APIs & Services → Library.
  2. Search for: Google Drive API.
  3. Open the API page.
  4. Click Enable.

Once enabled, your project can make requests to Google Drive.

Salesforce to Google Drive Integration Step 6

Step 4: Configure Salesforce Custom Settings

Custom Settings can be used to store integration-related values such as Client ID, Client Secret, Access Token, Refresh Token, and Folder IDs.

Procedure

  1. In Salesforce Setup, search for: Custom Settings.
  2. Create a new custom setting.
  3. Add the following fields:
Field NamePurpose
Client_Id__cGoogle Client ID
Client_Secret__cGoogle Client Secret
Access_Token__cOAuth Access Token
Refresh_Token__cOAuth Refresh Token
Folder_Id__cGoogle Drive Folder ID
Salesforce to Google Drive Integration Step 7

Step 5: Configure Remote Site Settings

Salesforce requires external endpoints to be whitelisted before making callouts.

Procedure

  1. Navigate to: Setup → Remote Site Settings.
  2. Create a new remote site record for Google Authentication: https://accounts.google.com
  3. Create another remote site record for Google APIs: https://www.googleapis.com
  4. Save both records.

These configurations allow Salesforce Apex callouts to communicate with Google services.

Step 6: Create a Destination Folder in Google Drive

A dedicated folder should be created to store files uploaded from Salesforce.

Procedure

  1. Open Google Drive.
  2. Click New.
  3. Select Folder.
  4. Enter a folder name.
  5. Click Create.
  6. Copy the Folder ID from the URL for later use in Apex code.
Salesforce to Google Drive Integration Step 8

Step 7: Authorize Salesforce to Access Google Drive

The first authentication process requires user consent and authorization.

Process Overview

  1. Generate an OAuth authorization URL.
  2. Redirect the user to Google's consent page.
  3. User grants access.
  4. Google returns an authorization code.
  5. Salesforce exchanges the code for access and refresh tokens.

OAuth Authorization Endpoint

https://accounts.google.com/o/oauth2/auth

Required parameters include:

  • Client ID
  • Redirect URI
  • Scope
  • Response Type
  • Access Type

After successful authorization, Google returns a temporary authorization code.

Step 8: Retrieve Access Token

Once the authorization code is received, Salesforce sends a POST request to Google's token endpoint.

Token Endpoint

https://accounts.google.com/o/oauth2/token

Request Parameters

ParameterDescription
codeAuthorization code
client_idGoogle Client ID
client_secretGoogle Client Secret
redirect_uriRedirect URL
grant_typeauthorization_code

The response contains the Access Token, Refresh Token, and Expiry Information. Store these values securely in Salesforce.

Step 9: Refresh Expired Access Tokens

Access tokens eventually expire. Salesforce can use the refresh token to generate a new access token automatically.

Refresh Endpoint

https://accounts.google.com/o/oauth2/token

Required Parameters

  • Client ID
  • Client Secret
  • Refresh Token
  • grant_type=refresh_token

The response returns a new access token without requiring user login.

Step 10: Generate Files from Salesforce

Salesforce can create reports and export them into formats such as Excel before uploading them to Google Drive.

Example Scenario

  1. Query a Salesforce report.
  2. Generate Excel output.
  3. Convert the report into a Blob.
  4. Prepare the file for upload.

Possible file types: Excel, PDF, CSV, Text Files.

Step 11: Create a File Record in Google Drive

Before uploading content, Google Drive requires a file entry to be created.

API Endpoint

https://www.googleapis.com/drive/v3/files

Metadata

Include:

  • File Name
  • MIME Type
  • Parent Folder ID

Google returns a unique File ID after creation.

Step 12: Upload File Content to Google Drive

Using the generated File ID, Salesforce uploads the actual document content.

Upload Endpoint

https://www.googleapis.com/upload/drive/v3/files/{FileId}

Process

  1. Send file content as Blob.
  2. Include OAuth access token.
  3. Execute HTTP PATCH request.
  4. Verify upload success.

After completion, the file becomes available in the specified Google Drive folder.

Benefits

  • Secure authentication using OAuth 2.0
  • Automated file management
  • Reduced Salesforce storage costs
  • Easy document sharing
  • Improved collaboration
  • Centralized document repository

Limitations

  • Requires Google Cloud configuration
  • OAuth token management is necessary
  • Google API usage quotas may apply
  • Additional development required for advanced features

Conclusion

Google Drive and Salesforce integration provides an efficient method for managing documents outside of Salesforce while maintaining easy accessibility. By leveraging Google Cloud Platform, OAuth authentication, Google Drive APIs, and Salesforce Apex callouts, organizations can automate file storage, improve collaboration, and optimize Salesforce storage usage. This integration is particularly beneficial for businesses that frequently generate reports, invoices, contracts, and customer documents within Salesforce and need a scalable external storage solution.

Topics:SalesforceGoogle DriveREST API

Ready to accelerate your digital transformation?

Partner with Subsel to build modern CRM, AI-enabled automation, and enterprise systems that scale.