Close Menu
SalesforceCodex
    Facebook X (Twitter) Instagram
    Trending
    • The Ultimate Guide to Data Cleanup Techniques for Salesforce
    • How to Leverage Model Context Protocol (MCP) to Enhance Salesforce AI
    • Top Mistakes Developers Make in Salesforce Apex Triggers
    • Introducing Agentforce3 to Salesforce Developers
    • The Ultimate Guide to Apex Order of Execution for Developers
    • How to Handle Bulkification in Apex with Real-World Use Cases
    • How to Confidently Manage Transactions in Salesforce Apex
    • Building a Dynamic Tree Grid in Lightning Web Component
    Facebook X (Twitter) Instagram
    SalesforceCodex
    Subscribe
    Saturday, August 2
    • Home
    • Salesforce Platform
      • Architecture
      • Apex
      • Lightning Web Components
      • Integration
      • Flows & Automation
      • Best Practices
      • Questions
      • News
      • Books Testimonial
    • Industries
      • Artificial Intelligence
    • Hire Me
    • Certification
      • How to Prepare for Salesforce Integration Architect Exam
      • Certification Coupons
    • Downloads
      • Salesforce Release Notes
      • Apex Coding Guidelines
    • About Us
      • Privacy Policy
    • Contact Us
    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 Sahni6 Mins Read

    How to Leverage Model Context Protocol (MCP) to Enhance Salesforce AI

    July 28, 2025
    By Dhanik Lal Sahni7 Mins Read

    Top Mistakes Developers Make in Salesforce Apex Triggers

    July 25, 2025
    By Dhanik Lal Sahni14 Mins Read

    The Ultimate Guide to Apex Order of Execution for Developers

    July 20, 2025
    Add A Comment
    Leave A Reply Cancel Reply

    Ranked #1 Salesforce Developer Blog by SalesforceBen.com
    SFBenTopDeveloper
    Ranked #4 Salesforce Developer Blog by ApexHours.com
    ApexHoursTopDevelopers
    Categories
    Archives
    Tags
    apex (116) apex best practices (5) apex code best practice (10) apex code optimization (6) Apex logging (4) apex rest (11) apex trigger best practices (6) architecture (22) Asynchronous apex (9) AWS (5) batch apex (10) best code practice (4) code optimization (9) custom metadata types (5) design principle (9) flow (16) google (6) google api (4) integration (19) integration architecture (6) lighting (8) lightning (66) lightning-combobox (5) lightning-datatable (10) lightning component (32) Lightning web component (64) lwc (53) named credential (8) news (4) optimize apex (5) optimize apex code (6) optimize apex trigger (5) Permission set (4) Queueable (9) queueable apex (4) rest api (23) salesforce (150) salesforce apex (52) salesforce api integration (5) Salesforce Interview Question (5) 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

    MailChimp

    Expert Salesforce Developer and Architect
    Ranked #1 SALESFORCE DEVELOPER BLOG BY SALESFORCEBEN.COM
    Featured on Top Salesforce Developer Blog By ApexHours
    Recent Posts
    • The Ultimate Guide to Data Cleanup Techniques for Salesforce
    • How to Leverage Model Context Protocol (MCP) to Enhance Salesforce AI
    • Top Mistakes Developers Make in Salesforce Apex Triggers
    • Introducing Agentforce3 to Salesforce Developers
    • The Ultimate Guide to Apex Order of Execution for Developers
    Ranked in Top Salesforce Blog by feedspot.com
    RSS Recent Stories
    • Top 10 Salesforce CRM Trends to Watch in 2025 July 18, 2025
    • Discover the Top 10 Salesforce AppExchange Apps to Boost Productivity July 10, 2025
    • 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
    Archives
    Categories
    Tags
    apex (116) apex best practices (5) apex code best practice (10) apex code optimization (6) Apex logging (4) apex rest (11) apex trigger best practices (6) architecture (22) Asynchronous apex (9) AWS (5) batch apex (10) best code practice (4) code optimization (9) custom metadata types (5) design principle (9) flow (16) google (6) google api (4) integration (19) integration architecture (6) lighting (8) lightning (66) lightning-combobox (5) lightning-datatable (10) lightning component (32) Lightning web component (64) lwc (53) named credential (8) news (4) optimize apex (5) optimize apex code (6) optimize apex trigger (5) Permission set (4) Queueable (9) queueable apex (4) rest api (23) salesforce (150) salesforce apex (52) salesforce api integration (5) Salesforce Interview Question (5) 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.