Salesforce Asked on December 14, 2021
As the title suggests, we use Named Credentials to connect to a external service, that service returns an access token we can use for a period of time. I wanted to know if there was some built in function to cache that token for x hours or do we need to build this using Apex?
When using OAuth, the Named Credentials automatically stores the Access Token and Refresh Token. When making a callout using Named Credentials, Apex will automatically try the Access Token first, and if it gets a 401, with an error response of invalid_token
, it will try the Refresh Token to get a new Access Token, and try again, and if that fails, then throws the appropriate error. This all happens behind the scenes without any effort on part of the developer.
For non OAuth tokens, such as API keys or something else, you need to arrange for your own storage. This could be a custom setting, custom metadata, platform cache, or another solution. You'll need to remember to keep this information secure by access controls and/or encrypting the token.
Answered by sfdcfox on December 14, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP