{"id":1726,"date":"2026-09-29T13:00:00","date_gmt":"2026-09-29T07:30:00","guid":{"rendered":"https:\/\/swapnilzambare.com\/blog\/named-credentials-in-apex-callouts\/"},"modified":"2026-11-15T11:31:51","modified_gmt":"2026-11-15T06:01:51","slug":"named-credentials-in-apex-callouts","status":"publish","type":"post","link":"https:\/\/swapnilzambare.com\/blog\/named-credentials-in-apex-callouts\/","title":{"rendered":"Named Credentials in Apex: Secure Callouts with External Credentials"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Named Credentials in Apex let your code call an external API without ever holding its URL, password or API key. The code just says callout:LearnHub, and Salesforce adds the address and the authentication for you. This keeps secrets out of code and makes moving between sandboxes and production much simpler.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this post, you will learn how Named Credentials, External Credentials, principals and permission sets fit together, and how Apex uses them. It builds on <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-rest-callouts-httprequest\/\">Apex REST callouts<\/a>, the admin view of <a href=\"https:\/\/swapnilzambare.com\/blog\/salesforce-named-credentials-external\/\">Named Credentials<\/a> and <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-secure-coding-xss-csrf-injection\/\">Apex secure coding<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What are Named Credentials in Apex?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A Named Credential stores the base URL of an external service and links to an External Credential, which stores how to log in. Named Credentials in Apex are used by writing callout:Name in the endpoint, such as callout:LearnHub\/v1\/students. At runtime, Salesforce builds the full URL and adds the right authentication headers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of an office building with a reception desk. You do not carry every company&#8217;s door key. Instead, you tell the receptionist which office you need, and they open the door for you, if you are on the visitor list. The Named Credential is the office address, the External Credential is the key, and the permission set is the visitor list.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Named Credentials in Apex Matter<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Secrets in code are one of the most common security findings. Here is why Named Credentials in Apex matter at Bright Path Tutors.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First, the LearnHub API key must never appear in Apex or in Git.<\/li>\n\n<li>Also, the sandbox calls LearnHub&#8217;s test URL, while production calls the live one.<\/li>\n\n<li>Next, only the integration user should be able to call PayQuick.<\/li>\n\n<li>OAuth tokens refresh automatically, so code never handles expiry.<\/li>\n\n<li>Finally, security reviews and Code Analyzer flag hard-coded secrets.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">So Named Credentials in Apex make callouts safer and easier to deploy.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How Named Credentials in Apex Work<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The setup has a few connected parts. First, an admin creates an External Credential with an authentication protocol, such as OAuth 2.0 or Custom. Next, they add a principal, which holds the actual secret, such as an API key. Then they give that principal to users through a permission set. After that, a Named Credential links the base URL to the External Credential. Finally, Apex calls callout:Name, and Salesforce adds the URL and the authentication at runtime.<\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/named-credentials-in-apex-callouts-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/named-credentials-in-apex-callouts-diagram-1-1024x640.png\" alt=\"Named Credentials in Apex diagram showing External Credential, principal, permission set, Named Credential and Apex\" class=\"wp-image-1724\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/named-credentials-in-apex-callouts-diagram-1-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/named-credentials-in-apex-callouts-diagram-1-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/named-credentials-in-apex-callouts-diagram-1-768x480.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">How the credential parts connect to your Apex code.<\/figcaption><\/figure>\n\n\n<h3 class=\"wp-block-heading\">External Credential<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The External Credential defines the authentication protocol. Options include OAuth 2.0 flows, custom headers, JWT and AWS Signature Version 4.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Principal<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A principal stores the secret values. A named principal shares one login for everyone, while a per-user principal stores a login for each user.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Permission Set Mapping<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Users can only use a principal granted through External Credential Principal Access in a permission set. Without it, the callout fails.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Named Credential<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The Named Credential holds the base URL and points to the External Credential. Its API name is what Apex writes after callout:.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Custom Headers and Formulas<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You can add headers, such as x-api-key, whose value is a formula like {!$Credential.LearnHub_Auth.ApiKey}. So the key is filled in at runtime.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Named Credential Parts at a Glance<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The table below sums up each part of Named Credentials in Apex and who owns it.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Part<\/th><th>Holds<\/th><th>Usually set by<\/th><\/tr><\/thead><tbody><tr><td>External Credential<\/td><td>Authentication protocol<\/td><td>Admin or developer<\/td><\/tr><tr><td>Principal<\/td><td>Secret values, such as a key<\/td><td>Admin<\/td><\/tr><tr><td>Permission set<\/td><td>Who may use the principal<\/td><td>Admin<\/td><\/tr><tr><td>Named Credential<\/td><td>Base URL and options<\/td><td>Admin or developer<\/td><\/tr><tr><td>Apex code<\/td><td>callout:Name plus the path<\/td><td>Developer<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">New Named Credentials vs Legacy Named Credentials<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The table below compares today&#8217;s model with the older legacy type.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>New model<\/th><th>Legacy model<\/th><\/tr><\/thead><tbody><tr><td>Authentication stored in<\/td><td>External Credential<\/td><td>Named Credential itself<\/td><\/tr><tr><td>Access control<\/td><td>Permission sets<\/td><td>Profile or global<\/td><\/tr><tr><td>Reuse one login for many URLs<\/td><td>Yes<\/td><td>No<\/td><\/tr><tr><td>Custom headers with formulas<\/td><td>Yes<\/td><td>Limited<\/td><\/tr><tr><td>Status<\/td><td>Recommended<\/td><td>Supported, not for new work<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">When to use which is clear. Build all new integrations on the new model. Move legacy credentials when you next change those integrations.<\/p>\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/named-credentials-in-apex-callouts-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/named-credentials-in-apex-callouts-diagram-2-1024x640.png\" alt=\"Named Credentials in Apex diagram comparing new and legacy Named Credentials\" class=\"wp-image-1725\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/named-credentials-in-apex-callouts-diagram-2-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/named-credentials-in-apex-callouts-diagram-2-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/named-credentials-in-apex-callouts-diagram-2-768x480.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">New model vs legacy Named Credentials.<\/figcaption><\/figure>\n\n\n<h2 class=\"wp-block-heading\">A Real Named Credentials in Apex Example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s set up Named Credentials in Apex for LearnHub at Bright Path Tutors. LearnHub expects an API key in an x-api-key header.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Configure the Credentials<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>In Setup, open Named Credentials, then the External Credentials tab, and click New.<\/li>\n\n<li>Enter Label LearnHub Auth, Name LearnHub_Auth and Authentication Protocol Custom.<\/li>\n\n<li>Add a named principal called Integration with an authentication parameter ApiKey and the key value.<\/li>\n\n<li>Open the Named Credentials tab and create LearnHub with URL https:\/\/api.learnhub.example and External Credential LearnHub Auth.<\/li>\n\n<li>Add a custom header x-api-key with value {!$Credential.LearnHub_Auth.ApiKey}.<\/li>\n\n<li>In the Integration permission set, add the principal under External Credential Principal Access.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Use It from Apex<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>public with sharing class LearnHubProgressService {\n    public static String getProgress(String learnHubId) {\n        HttpRequest req = new HttpRequest();\n        \/\/ Salesforce adds the base URL and the x-api-key header\n        req.setEndpoint('callout:LearnHub\/v1\/students\/' +\n            EncodingUtil.urlEncode(learnHubId, 'UTF-8') + '\/progress');\n        req.setMethod('GET');\n\n        HttpResponse res = new Http().send(req);\n        if (res.getStatusCode() == 401) {\n            throw new CalloutException('Check the LearnHub principal and permission set.');\n        }\n        return res.getBody();\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The code holds no URL and no key. It also encodes the Id before adding it to the path, so odd characters cannot change the request.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Test It with a Mock<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>@IsTest\nprivate class LearnHubProgressServiceTest {\n    private class ProgressMock implements HttpCalloutMock {\n        public HttpResponse respond(HttpRequest req) {\n            Assert.isTrue(req.getEndpoint().startsWith('callout:LearnHub\/'));\n            HttpResponse res = new HttpResponse();\n            res.setStatusCode(200);\n            res.setBody('{\"completed\":7,\"total\":10}');\n            return res;\n        }\n    }\n\n    @IsTest\n    static void returnsProgress() {\n        Test.setMock(HttpCalloutMock.class, new ProgressMock());\n        String body = LearnHubProgressService.getProgress('LH-20931');\n        Assert.areEqual('{\"completed\":7,\"total\":10}', body);\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The mock checks that the code used the Named Credential and returns fake progress. So the test passes without any real network call.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here is the test result.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>LearnHubProgressServiceTest.returnsProgress  Pass  (38 ms)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Named Credentials in Apex Across Sandboxes<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Each org keeps its own credential values, so the same Apex works everywhere. After a sandbox refresh, point the Named Credential at the test URL and enter test keys. Deployments carry the Named Credential and External Credential, but never the secret values.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with Named Credentials in Apex<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Forgetting the permission set mapping, so callouts fail with a 401.<\/li>\n\n<li>Writing the full URL in Apex instead of callout:Name.<\/li>\n\n<li>Putting API keys in custom settings or custom metadata.<\/li>\n\n<li>Not enabling formulas in headers when using {!$Credential} values.<\/li>\n\n<li>Expecting secrets to deploy with metadata.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Named Credentials in Apex<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use the new External Credential model for all new work.<\/li>\n\n<li>Give principals only to the integration permission set.<\/li>\n\n<li>Use OAuth client credentials or JWT where the service supports them.<\/li>\n\n<li>Keep one service class per Named Credential.<\/li>\n\n<li>Document each credential&#8217;s owner and renewal date.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Add a second principal for a different LearnHub account used by the support team. Hint: create a new named principal, add it to a Support permission set, and check which principal runs with each user.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Most Asked Interview Questions on Named Credentials in Apex<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Secure callouts are a common interview topic. Here are the 22 questions asked most about Named Credentials in Apex.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Basic Questions on Named Credentials in Apex<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q1: What is a Named Credential?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A Setup record that stores an external service&#8217;s base URL and links to its authentication.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q2: What is an External Credential?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The record that defines how to authenticate, such as OAuth 2.0 or custom headers.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q3: How does Apex use a Named Credential?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It sets the endpoint to callout:Name plus the path.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q4: What is a principal?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The part of an External Credential that stores the actual secret values.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q5: What is the difference between named and per-user principals?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A named principal shares one login, while a per-user principal stores each user&#8217;s own login.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q6: How do users get access to a principal?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Through External Credential Principal Access in a permission set.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q7: Do you still need a Remote Site Setting?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">No, because the Named Credential already tells Salesforce to trust that URL.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Code and Scenario Questions on Named Credentials in Apex<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q8: A callout returns 401 after deployment. What do you check first?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The principal values in that org and the permission set mapping for the running user.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q9: How do you send an API key header without code?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Add a custom header with a {!$Credential.ExternalCredential.Parameter} formula.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q10: How do you test code that uses a Named Credential?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use HttpCalloutMock, because tests never reach the real endpoint.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q11: How do the same classes call test and live URLs?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Each org has its own Named Credential URL, so the code stays the same.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q12: Can Flow use the same Named Credential?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Yes, so Flow HTTP callouts and External Services can share it with Apex.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q13: Are secrets included in deployments?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">No, because only the metadata moves, and you enter secrets in each org.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q14: How do you call two paths on the same service?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use the same Named Credential with different paths after callout:Name.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Advanced Questions on Named Credentials in Apex<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q15: Why is the new model better than legacy Named Credentials?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It separates URL and authentication, reuses logins and controls access with permission sets.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q16: Which OAuth flow suits a server integration?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Client credentials or JWT bearer, because no user needs to log in.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q17: Can Apex create Named Credentials?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Yes, through ConnectApi Named Credentials methods, though most teams use Setup or metadata.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q18: How are OAuth tokens refreshed?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Salesforce refreshes them automatically when the External Credential uses OAuth.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q19: Why encode values added to the callout path?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Because unencoded input can change the URL and call a different resource.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q20: How do you rotate an API key?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Update the principal&#8217;s parameter value, and no code changes are needed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q21: How would you restrict a callout to one integration user?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Map the principal only in a permission set given to that user.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q22: Where else do Named Credentials help?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">They support Salesforce Connect, External Services and Flow, so one secure setup serves many tools.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/platform\/apex-dev\/references\/apex-dev\/apex-callouts-named-credentials.html\" target=\"_blank\" rel=\"noopener noreferrer\">Named Credentials as Callout Endpoints (Apex Developer Guide)<\/a><\/li>\n\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/platform\/named-credentials\/guide\/get-started.html\" target=\"_blank\" rel=\"noopener noreferrer\">Get Started with Named Credentials (Named Credentials Developer Guide)<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Using Named Credentials in Apex keeps URLs and secrets out of code.<\/li>\n\n<li>External Credentials define authentication, and principals hold secrets.<\/li>\n\n<li>Permission sets decide who can use each principal.<\/li>\n\n<li>Apex calls callout:Name plus the path.<\/li>\n\n<li>Secrets never deploy, so set them in each org.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">So far Salesforce has called others. Next, let others call your own Apex. Read our guide to <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-rest-services-restresource\/\">Apex REST services with @RestResource<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Named Credentials in Apex let your code call an external API without ever holding its URL, password or API key. The code just says&hellip;<\/p>\n","protected":false},"author":1,"featured_media":1723,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[246,8,96],"tags":[98,81,26],"swapz_series":[],"class_list":["post-1726","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-integration-apis","category-salesforce","category-salesforce-developer","tag-apex","tag-integration","tag-intermediate"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Named Credentials in Apex: Secure Callouts<\/title>\n<meta name=\"description\" content=\"Named Credentials in Apex explained: External Credentials, principals, permission sets, callout: syntax, custom headers, testing and 22 interview Q&amp;A.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/swapnilzambare.com\/blog\/named-credentials-in-apex-callouts\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Named Credentials in Apex: Secure Callouts\" \/>\n<meta property=\"og:description\" content=\"Named Credentials in Apex explained: External Credentials, principals, permission sets, callout: syntax, custom headers, testing and 22 interview Q&amp;A.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/swapnilzambare.com\/blog\/named-credentials-in-apex-callouts\/\" \/>\n<meta property=\"og:site_name\" content=\"Swapnil Zambare - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-29T07:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-15T06:01:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/named-credentials-in-apex-callouts-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Swapnil Zambare\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Swapnil Zambare\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/named-credentials-in-apex-callouts\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/named-credentials-in-apex-callouts\\\/\"},\"author\":{\"name\":\"Swapnil Zambare\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/10b09224c8bcc562716e86789427592a\"},\"headline\":\"Named Credentials in Apex: Secure Callouts with External Credentials\",\"datePublished\":\"2026-09-29T07:30:00+00:00\",\"dateModified\":\"2026-11-15T06:01:51+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/named-credentials-in-apex-callouts\\\/\"},\"wordCount\":1656,\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/named-credentials-in-apex-callouts\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/named-credentials-in-apex-callouts-featured.png\",\"keywords\":[\"Apex\",\"Integration\",\"Intermediate\"],\"articleSection\":[\"Integration and APIs\",\"Salesforce\",\"Salesforce Developer\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/named-credentials-in-apex-callouts\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/named-credentials-in-apex-callouts\\\/\",\"name\":\"Named Credentials in Apex: Secure Callouts\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/named-credentials-in-apex-callouts\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/named-credentials-in-apex-callouts\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/named-credentials-in-apex-callouts-featured.png\",\"datePublished\":\"2026-09-29T07:30:00+00:00\",\"dateModified\":\"2026-11-15T06:01:51+00:00\",\"description\":\"Named Credentials in Apex explained: External Credentials, principals, permission sets, callout: syntax, custom headers, testing and 22 interview Q&A.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/named-credentials-in-apex-callouts\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/named-credentials-in-apex-callouts\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/named-credentials-in-apex-callouts\\\/#primaryimage\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/named-credentials-in-apex-callouts-featured.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/named-credentials-in-apex-callouts-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Named Credentials in Apex featured image: title card with an integration code example\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/named-credentials-in-apex-callouts\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Named Credentials in Apex: Secure Callouts with External Credentials\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"name\":\"Swapnil Zambare - Blog\",\"description\":\"Salesforce &amp; Tech Guides\",\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\",\"name\":\"Swapnil Zambare - Blog\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"width\":512,\"height\":512,\"caption\":\"Swapnil Zambare - Blog\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/theSwapnilZambare\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/10b09224c8bcc562716e86789427592a\",\"name\":\"Swapnil Zambare\",\"sameAs\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\"],\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/author\\\/swapnil-zambare\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Named Credentials in Apex: Secure Callouts","description":"Named Credentials in Apex explained: External Credentials, principals, permission sets, callout: syntax, custom headers, testing and 22 interview Q&A.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/swapnilzambare.com\/blog\/named-credentials-in-apex-callouts\/","og_locale":"en_US","og_type":"article","og_title":"Named Credentials in Apex: Secure Callouts","og_description":"Named Credentials in Apex explained: External Credentials, principals, permission sets, callout: syntax, custom headers, testing and 22 interview Q&A.","og_url":"https:\/\/swapnilzambare.com\/blog\/named-credentials-in-apex-callouts\/","og_site_name":"Swapnil Zambare - Blog","article_published_time":"2026-09-29T07:30:00+00:00","article_modified_time":"2026-11-15T06:01:51+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/named-credentials-in-apex-callouts-featured.png","type":"image\/png"}],"author":"Swapnil Zambare","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Swapnil Zambare","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/swapnilzambare.com\/blog\/named-credentials-in-apex-callouts\/#article","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/named-credentials-in-apex-callouts\/"},"author":{"name":"Swapnil Zambare","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/10b09224c8bcc562716e86789427592a"},"headline":"Named Credentials in Apex: Secure Callouts with External Credentials","datePublished":"2026-09-29T07:30:00+00:00","dateModified":"2026-11-15T06:01:51+00:00","mainEntityOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/named-credentials-in-apex-callouts\/"},"wordCount":1656,"publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/named-credentials-in-apex-callouts\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/named-credentials-in-apex-callouts-featured.png","keywords":["Apex","Integration","Intermediate"],"articleSection":["Integration and APIs","Salesforce","Salesforce Developer"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/swapnilzambare.com\/blog\/named-credentials-in-apex-callouts\/","url":"https:\/\/swapnilzambare.com\/blog\/named-credentials-in-apex-callouts\/","name":"Named Credentials in Apex: Secure Callouts","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/named-credentials-in-apex-callouts\/#primaryimage"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/named-credentials-in-apex-callouts\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/named-credentials-in-apex-callouts-featured.png","datePublished":"2026-09-29T07:30:00+00:00","dateModified":"2026-11-15T06:01:51+00:00","description":"Named Credentials in Apex explained: External Credentials, principals, permission sets, callout: syntax, custom headers, testing and 22 interview Q&A.","breadcrumb":{"@id":"https:\/\/swapnilzambare.com\/blog\/named-credentials-in-apex-callouts\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/swapnilzambare.com\/blog\/named-credentials-in-apex-callouts\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/named-credentials-in-apex-callouts\/#primaryimage","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/named-credentials-in-apex-callouts-featured.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/named-credentials-in-apex-callouts-featured.png","width":2400,"height":1260,"caption":"Named Credentials in Apex featured image: title card with an integration code example"},{"@type":"BreadcrumbList","@id":"https:\/\/swapnilzambare.com\/blog\/named-credentials-in-apex-callouts\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/swapnilzambare.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Named Credentials in Apex: Secure Callouts with External Credentials"}]},{"@type":"WebSite","@id":"https:\/\/swapnilzambare.com\/blog\/#website","url":"https:\/\/swapnilzambare.com\/blog\/","name":"Swapnil Zambare - Blog","description":"Salesforce &amp; Tech Guides","publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/swapnilzambare.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/swapnilzambare.com\/blog\/#organization","name":"Swapnil Zambare - Blog","url":"https:\/\/swapnilzambare.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","width":512,"height":512,"caption":"Swapnil Zambare - Blog"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.linkedin.com\/in\/theSwapnilZambare"]},{"@type":"Person","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/10b09224c8bcc562716e86789427592a","name":"Swapnil Zambare","sameAs":["https:\/\/swapnilzambare.com\/blog"],"url":"https:\/\/swapnilzambare.com\/blog\/author\/swapnil-zambare\/"}]}},"_links":{"self":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/1726","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/comments?post=1726"}],"version-history":[{"count":1,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/1726\/revisions"}],"predecessor-version":[{"id":2331,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/1726\/revisions\/2331"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media\/1723"}],"wp:attachment":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media?parent=1726"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/categories?post=1726"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/tags?post=1726"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=1726"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}