Skip to main content

HTTP Callouts

Explore practical guides and implementation patterns for this topic.

Posts

Apex Development

How to Use Named Credentials in Salesforce Apex: Step-by-Step Guide

💬 In plain words: An Apex callout is Salesforce making a phone call to an outside system's API. Named Credentials and External Credentials are your secure phonebook. They store the address (URL) and the login details (like OAuth tokens or an API key), so your code holds no secrets at all. Your code just says callout:My_Named_Credential , and Salesforce adds the login details for you. And a Lightning Web Component (LWC) should never make this call straight from the browser. It should ask Apex to make it. 📌 Example: A user clicks "Check Credit Score" in an LWC. The LWC calls an Apex method. Apex makes the callout to callout:CreditAPI/score through a Named Credential. The browser never sees the API URL or the secret key. If the API password changes, an admin updates it in Setup. No code change, no deployment.
Read article
Topic Apex
Apex Development

Understanding Multipart Data and Boundaries for File Uploads in Salesforce Apex

In plain words: When you send data via an HTTP request, standard JSON usually works fine. However, if you need to upload a binary file (like a PDF or image) alongside text form fields in a single request, you must use a format called multipart/form-data . A boundary is a unique text divider placed between each piece of data so the receiving server knows where one file ends and the next form field begins. In Salesforce development, integrating with external REST APIs to upload files or documents is a frequent requirement. When the target API expects a file payload combined with metadata, simple JSON strings won't cut it. You need to construct a multipart HTTP request. Let's dive into how multipart data and boundary strings work under the hood, and look at a clean Apex implementation for handling file uploads.
Read article