October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

Salesforce Apex Callouts: A Simple Guide to REST API Integration

A practical guide to planning an Apex REST callout, configuring modern Salesforce credentials, handling failures, and testing without production credentials.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To call an external REST API from Apex, configure an External Credential for authentication, connect it to a Named Credential for the endpoint, grant users access to the credential principal, then send an Apex HTTP request through that Named Credential. Use Salesforce’s modern extensible Named Credentials rather than the legacy model, which Salesforce says is deprecated and will be discontinued in a future release.

Decide whether Apex is the right layer

For common Salesforce record and metadata access, first check whether Lightning Data Service (LDS) supports the entity and operation. LDS covers many typical use cases; Apex is appropriate when you need Salesforce APIs or entities outside LDS’s supported subset. For calls from Apex to external services, Salesforce’s Call APIs from Apex guidance explains the available approach and security considerations.

As an Amazon Associate I earn from qualifying purchases.

Be precise about which API you are calling. Salesforce advises using its standard REST or SOAP APIs—not Connect REST API—for sObject extraction, migrations, synchronization, analytics, and record queries. See Connect REST API Limits for the distinction and related limits guidance.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Plan the integration before configuring it

Before building the callout, establish the target API’s base endpoint, required HTTP method, resource path, request and response formats, authentication scheme, and expected error behavior. These choices determine the credential configuration and the shape of the Apex request. Salesforce’s REST API Quick Start is a starting point for understanding REST API requests.

  • Identify the service and the exact resource the callout must reach.
  • Confirm whether the service expects JSON, another payload format, or no request body.
  • Find out how the service authenticates requests and which access it grants.
  • Agree on how your code should handle unsuccessful responses, throttling, and malformed payloads.

Configure modern Named Credentials

Salesforce separates the endpoint from authentication and access control. A Named Credential identifies the endpoint and transport configuration. An External Credential defines the authentication configuration; its principal maps access to permissions. User external credentials store tokens encrypted. Follow Salesforce’s Get Started with Named Credentials documentation for the current setup flow.

  1. Create an External Credential. Choose the authentication protocol and configure the principal appropriate for the external API.
  2. Create a Named Credential. Set its endpoint to the API host and associate it with the External Credential.
  3. Grant access selectively. Give the relevant users permission to use the External Credential principal. Avoid granting the principal more broadly than the integration requires.
  4. Verify in a non-production org. Test the configured credentials in a sandbox or testing org before using them in production.

Named Credentials let Apex make authenticated calls without embedding endpoint authentication details directly in the callout code. Salesforce cautions developers to review this capability carefully: sessions created through Lightning are not generally enabled for API access. Do not assume that a user’s Lightning session can stand in for the API authentication configured for an integration.

Send the request from Apex

In Apex, construct an HTTP request and direct it through the configured Named Credential, then inspect the HTTP response. The Named Credential supplies the configured endpoint and authentication context; your code is responsible for the resource path, method, any required headers or body, and interpreting the response.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The current Apex syntax for HttpRequest, HttpResponse, Http.send, and JSON parsing should be taken from the current Apex Developer Guide. The Salesforce sources cited here establish the credential architecture but do not verify a complete current Apex code example, so this guide does not provide unverified syntax.

Validate responses and plan for failures

Do not treat a completed HTTP exchange as proof that the operation succeeded. Check the returned status code, confirm that the payload has the shape your code expects, and define how failures are surfaced or recovered. Retry only when the operation and API semantics make a retry safe; avoid blindly repeating writes that could create duplicate effects.

For Connect REST API, Salesforce documents HTTP 503 responses when a rate limit is exceeded and recommends handling them gracefully. Most Connect REST API requests share Salesforce platform API limits; some Chatter resources instead have a per-user, per-application, per-hour limit. These limits can change without notice, so consult the current Connect REST API limits documentation rather than relying on a universal quota. These details concern Connect REST API and should not be mistaken for a fixed Apex callout allowance.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Test the integration without exposing production credentials

Salesforce recommends verifying target-org credentials in a sandbox or testing org and warns against testing credentials in production. Use test credentials and a test endpoint where possible, and verify both successful responses and relevant failure handling before deployment. Salesforce’s Test Credentials in the Target Org documentation describes this credential check.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For Apex tests, Salesforce’s 2018 Platform Developer II exam guide references Test.setMock() and HttpCalloutMock for callout testing. Because that guide is dated, verify the current syntax and test APIs against Salesforce’s current Apex documentation before adopting an example: Certified Platform Developer II Exam Guide (2018).

Choose the right Salesforce API

Need Approach Why
Common Salesforce record or metadata access Check Lightning Data Service first LDS supports many typical record and metadata use cases.
Salesforce entity or operation outside LDS’s supported subset Apex Apex can handle other Salesforce APIs and entities.
External API call from Apex Modern Named Credential with an External Credential Separates endpoint configuration from authentication and permission mapping.
sObject extraction, migrations, synchronization, analytics, or record queries Salesforce REST or SOAP API, rather than Connect REST API Salesforce recommends the standard REST or SOAP APIs for these use cases.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.