Close Menu
SalesforceCodex
    Facebook X (Twitter) Instagram
    Trending
    • 10 Salesforce Chrome Extensions to Boost Your Productivity
    • How to Build a Generic Modal Window in Lightning Web Component
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    • How to Suppress PMD Warnings in Salesforce Apex
    • Top 10 PMD Issues Salesforce Developers Should Focus on in Apex
    Facebook X (Twitter) Instagram
    SalesforceCodex
    Subscribe
    Saturday, June 14
    • Home
    • Architecture
    • Salesforce
      • News
      • Apex
      • Integration
      • Books Testimonial
    • Questions
    • Certification
      • How to Prepare for Salesforce Integration Architect Exam
      • Certification Coupons
    • Integration Posts
    • Downloads
    • About Us
      • Privacy Policy
    SalesforceCodex
    Home»Salesforce»Integration»How to Use Graph API for Outlook-Salesforce Connection

    How to Use Graph API for Outlook-Salesforce Connection

    Dhanik Lal SahniBy Dhanik Lal SahniFebruary 22, 2025No Comments5 Mins Read
    Facebook Twitter Pinterest LinkedIn Tumblr Email
    Outlook-Salesforce Connection
    Share
    Facebook Twitter LinkedIn Pinterest Email

    In the world of business, effective synchronization between Outlook and Salesforce for managing emails, contacts, and calendar events is essential. Salesforce and Outlook working together sounds excellent. Imagine your sales personnel don’t have to go from one platform to the other to check for emails, send follow ups, or log customer interactions. It would be a breakthrough, wouldn’t it?

    That is exactly what this Outlook-Salesforce Connection using the Graph API does! With Microsoft Graph API we can establish a secure connection between Outlook and Salesforce which enables pulling of emails, sending of emails, and even calendar synchronization without any manual effort needed. This post will guide you in integrating Outlook-Salesforce to fetch emails.

    Salesforce can also be integrated within Outlook using the code approach feature. For a complete guide, see Set Up the Integration with Outlook.

    Let us focus here on integrating Outlook into Salesforce using REST API. We will go through each step one by one.

    • Register an App in Microsoft Azure
    • Set Up Outlook API Permissions
    • Configure Salesforce Named Credentials
    • Create an Apex Class for OAuth Token Retrieval
    • Fetch Outlook Emails Using REST API
    • Test Outlook Integration

    1. Register an App in Microsoft Azure

    To integrate MS Outlook into Salesforce, we must create an app in Microsoft Azure.

    Azure App Registration | Outlook Integration
    1. Go to the Microsoft Azure Portal.
    2. Navigate to Azure Active Directory (Microsoft Entra Id) > App Registrations.
    3. Click on New Registration and enter:
      • Name: Any meaningful name.
      • Supported account types: Choose Accounts in any organizational directory (Any Microsoft Entra ID tenant – Multitenant) and personal Microsoft accounts (e.g. Skype, Xbox)
      • Redirect URI: Choose Web and put your Salesforce domain (e.g., https://your-salesforce-instance.com) in web url.
    4. Enter Register to create app.
    5. After registration, open the created app.
    6. Navigate Client credentials -> Client Secrets
    7. Click on New Client Secret
      • Description- Enter SFAppSecret
      • Expires – Select 365 days (12 Months)
    8. This will generate a client secret.
      • It will generate a Secret Value and Secret ID. Secret Value will be used in Salesforce Auth Provider.

    2. Set Up Outlook API Permissions

    Microsoft Graph API provides access to Microsoft cloud services. Custom or external applications can use this API to connect data to enhance organization efficiency. We can provide specific API access to applications using the API permission feature.

    Outlook-Salesforce Connection | Outlook-Salesforce Integration
    1. In the API Permissions section, click Add a Permission.
    2. Select Microsoft Graph and choose:
      • Mail.Read
      • Mail.ReadWrite
      • Mail.Send
      • User.Read
      • Mail.ReadBaic
      • Mail.ReadBasicAll
    3. Click Grant Admin Consent.

    3. Configure Salesforce Named Credentials

    Configure Named Credential in Salesforce to integrate Outlook API. We will use client secrets created in Step 1. We will first create an a Auth Provider and then we will create named credential.

    3.1 Create External Credential

    External Credentials hold all information to connect external systems. Let us create external credentials to hold Azure credentials.

    External Credential | Salesforce Named Credential
    • Navigate to Salesforce Setup -> Named Credential-> External Credential
    • Label – Microsoft EC
    • Name – MicrosoftEC
    • Authentication Protocol – Custom
    • Save this External Credential
    • Add Principals
      • Parameter Name – Microsoft Principal
      • Sequence Number – 1
      • *Identity Type – Named Principal
      • Authentication Parameters
        • Parameter 1
          • Name – ClientSecret
          • Value – Put secret value from the Azure Client Secret feature.
        • Parameter 2
          • Name – ClientID
          • Value – Put Application (client) ID from Azure App
    • Create a Permission Set
      • Add this External Credential to External Credential Principal Access
      • Assign this permission to required user.
      • For the demo, assign this to yourself

    3.2 Create Named Credential

    Named Credential helps us authenticate external API. It holds all authentication parameters to integrate external app/API.

    Salesforce-Outlook Integration | Named Credential
    • Navigate to Salesforce Setup -> Named Credential
    • Click New
      • Label – Microsoft NC
      • Name – MicrosoftNC
      • Url – Put Url https://login.microsoftonline.com/{tenantId}/oauth2/v2.0/token. You can get TenantId from Azure Portal.
      • *External Credential – Microsoft EC
      • Allow Formulas in HTTP Header – Checked
      • Allow Formulas in HTTP Body – Checked
      • Generate Authorization Header – Unchecked
    • Click Save

    4. Create Apex Class to get Authentication Token

    Create an apex class to get a Microsoft Graph API access token. We have used external Credentials parameters to pass secure authentication parameters. You can check our other post Accessing External Credential Parameters of Named Credential in Salesforce Apex to retrieve parameter values from external credentials.

    5. Fetch Outlook Emails Using REST API

    Create an apex class OutlookEmailService to fetch all emails for a specific user. We need the azure portal user-id. It can be retrieved from the user page.

    This class uses the above-created OutlookAuthService class to get a token. We are fetching emails and putting them into a custom Outlook message object. You can use messages based on your requirements.

    6. Test Outlook Integration

    We can test outlook integration by calling OutlookEmailService.getEmails. This will insert email information in the Outlook Message object. You can use your logic to handle email information.

    Summary

    Integrating Outlook with Salesforce using REST API allows seamless email synchronization, contact management, and event handling. We can use Microsoft Graph API to authenticate, fetch Outlook emails, and send messages programmatically.

    References

    • Accessing External Credential Parameters of Named Credential in Salesforce Apex
    • Use the Microsoft Graph API

    Related Posts

    • Generic Apex class for Calling External System
    • How to Correctly Publish Platform Event Using Salesforce Apex
    • Best Practices to Avoid Hardcoding in Apex for Cleaner Salesforce Code
    • Publish Platform Events from ASP.NET
    • Uploading Files to Microsoft One Drive using Apex
    • Automating data synchronization between Salesforce and Amazon Seller
    • AWS Signature 4 Signing in Salesforce
    • Download the S3 File in Salesforce using AWS Signature Version 4.0
    • Use Named Credential to Upload File in S3

    apex microsoft microsoft azure portal microsoft graph api outlook integration salesforce salesforce apex salesforce outlook
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleEnhancing Performance with File Compression in Apex
    Next Article Top 10 PMD Issues Salesforce Developers Should Focus on in Apex
    Dhanik Lal Sahni
    • Website
    • Facebook
    • X (Twitter)

    With over 18 years of experience in web-based application development, I specialize in Salesforce technology and its ecosystem. My journey has equipped me with expertise in a diverse range of technologies including .NET, .NET Core, MS Dynamics CRM, Azure, Oracle, and SQL Server. I am dedicated to staying at the forefront of technological advancements and continuously researching new developments in the Salesforce realm. My focus remains on leveraging technology to create innovative solutions that drive business success.

    Related Posts

    By Dhanik Lal Sahni9 Mins Read

    10 Salesforce Chrome Extensions to Boost Your Productivity

    June 1, 2025
    By Dhanik Lal Sahni4 Mins Read

    How to Build a Generic Modal Window in Lightning Web Component

    May 26, 2025
    By Dhanik Lal Sahni6 Mins Read

    Top 10 Salesforce Flow Features of Salesforce Summer ’25

    May 11, 2025
    Add A Comment
    Leave A Reply Cancel Reply

    Ranked #1 SALESFORCE DEVELOPER BLOG BY SALESFORCEBEN.COM
    Featured on Top Salesforce Developer Blog By ApexHours
    Recent Posts
    • 10 Salesforce Chrome Extensions to Boost Your Productivity
    • How to Build a Generic Modal Window in Lightning Web Component
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    Ranked in Top Salesforce Blog by feedspot.com
    RSS Recent Stories
    • Top 20 Salesforce Data Cloud Interview Questions & Answers for Admins June 5, 2025
    • How to Connect Excel to Salesforce to Manage Your Data and Metadata February 9, 2025
    • Difference Between With Security and Without Security in Apex January 2, 2025
    • Top Reasons to Love Salesforce Trailhead: A Comprehensive Guide December 5, 2024
    • How to Utilize Apex Properties in Salesforce November 3, 2024
    Archives
    Categories
    Tags
    apex (111) apex code best practice (8) apex rest (11) apex trigger best practices (4) architecture (22) Asynchronous apex (9) AWS (5) batch apex (9) batch processing (4) code analysis (3) code optimization (8) custom metadata types (5) design principle (9) flow (15) future method (4) google (6) google api (4) integration (19) integration architecture (6) lighting (8) lightning (65) lightning-combobox (5) lightning-datatable (10) lightning component (31) Lightning web component (63) lwc (52) named credential (8) news (4) optimize apex code (4) optimize apex trigger (3) Permission set (4) pmd (3) Queueable (9) rest api (23) S3 Server (4) salesforce (142) salesforce apex (47) salesforce api (4) salesforce api integration (5) Salesforce Interview Question (4) salesforce news (5) salesforce question (5) solid (6) tooling api (5) Winter 20 (8)

    Get our newsletter

    Want the latest from our blog straight to your inbox? Chucks us your detail and get mail when new post is published.
    * indicates required

    Facebook X (Twitter) Instagram Pinterest YouTube Tumblr LinkedIn Reddit Telegram
    © 2025 SalesforceCodex.com. Designed by Vagmine Cloud Solution.

    Type above and press Enter to search. Press Esc to cancel.

    Ad Blocker Enabled!
    Ad Blocker Enabled!
    Our website is made possible by displaying online advertisements to our visitors. Please support us by disabling your Ad Blocker.