Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      June 2, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      June 2, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      June 2, 2025

      How To Prevent WordPress SQL Injection Attacks

      June 2, 2025

      How Red Hat just quietly, radically transformed enterprise server Linux

      June 2, 2025

      OpenAI wants ChatGPT to be your ‘super assistant’ – what that means

      June 2, 2025

      The best Linux VPNs of 2025: Expert tested and reviewed

      June 2, 2025

      One of my favorite gaming PCs is 60% off right now

      June 2, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      `document.currentScript` is more useful than I thought.

      June 2, 2025
      Recent

      `document.currentScript` is more useful than I thought.

      June 2, 2025

      Adobe Sensei and GenAI in Practice for Enterprise CMS

      June 2, 2025

      Over The Air Updates for React Native Apps

      June 2, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      You can now open ChatGPT on Windows 11 with Win+C (if you change the Settings)

      June 2, 2025
      Recent

      You can now open ChatGPT on Windows 11 with Win+C (if you change the Settings)

      June 2, 2025

      Microsoft says Copilot can use location to change Outlook’s UI on Android

      June 2, 2025

      TempoMail — Command Line Temporary Email in Linux

      June 2, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»Securely Store API, Bearer and Auth Tokens with Platform Cache

    Securely Store API, Bearer and Auth Tokens with Platform Cache

    May 29, 2025

    Imagine you are retrieving an API key/Bearer token from an external system to make a new callout to another external system. But there is one issue: you cannot determine when the new callout will take place, so you need to store the token value somewhere in your org for later use. Probably you will be thinking of storing it in your custom object or custom metadata. But creating a separate object/metadata for such a case may not be an efficient way. Then what? I think this is where Platform Cache helps you. Platform Cache provides temporary storage for such data in such cases. You can set up your platform cache by following the steps outlined in this trailhead. Here, I will explain how you can use the platform cache for this use case: I expect that you have already configured your platform cache in your dev org. Now suppose, you receive a bearer token from one API to pass into another callout after sometime, so you can store that access token in the Platform cache and avoid the hassle of creating a separate custom object/metadata or Custom Setting (Although you cannot update a Custom Metadata/Setting using Apex code).

    The Trailhead referenced in this article is crucial for understanding and setting up the platform cache. If you have not gone through the trailhead, then stop here and complete the trailhead first.

    How to Use Platform Cache to Fetch a Bearer Token

    How to fetch a bearer token and save it into the Platform cache using Apex:

    Picture1

    Now, you can fetch the bearer token from the Platform cache and use it in your next callout with the following code:

    Picture2 Picture3

     

    Remember, Platform Cache provides temporary storage, and data can be evicted from it because of memory pressure. Platform Cache does not guarantee the determined lifetime of the value stored; therefore, it is better not to store any value with an extended validity or sensitive information.

    Although platform cache is used to improve performance by evading unnecessary repeated API calls, there are a few concerns about using the Platform cache.

    When Not to Use Platform Cache

    • If the value contains sensitive information
    • If the value has to be stored for the long term
    • If you need environment-specific secret management

    References

    External System used: https://www.reqres.in
    Technology used: Salesforce

    Source: Read More 

    Hostinger
    Facebook Twitter Reddit Email Copy Link
    Previous ArticleHuman Biases – How Smart Teams Can Still Make Dumb Decisions
    Next Article The Urgent Call for Responsible AI: Why We Can’t Afford to Wait – Part 1

    Related Posts

    Development

    A Beginner’s Guide to Graphs — From Google Maps to Chessboards

    June 2, 2025
    Development

    How to Code Linked Lists with TypeScript: A Handbook for Developers

    June 2, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Distribution Release: CachyOS 250330

    News & Updates

    Microsoft Copilot is here to save you from having to create PowerPoint slides

    News & Updates

    HotPage: Story of a signed, vulnerable, ad-injecting driver

    Development

    Frontend Roadmap 2025

    Web Development
    Hostinger

    Highlights

    Too many tabs? Try these browsers with better tab management than Chrome

    February 5, 2025

    Stop wasting time searching for tabs every day. These four browsers with the best built-in…

    Apple WWDC 2025 keynote scheduled: What to expect from iOS 19, VisionOS 3, and more

    May 20, 2025

    Microsoft might kill the Surface Laptop Studio as production is quietly halted

    May 16, 2025

    CVE-2025-4996 – Intelbras RF 301K Cross-Site Scripting Vulnerability

    May 20, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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