Skip to main content

REST API

Explore practical guides and implementation patterns for this topic.

Posts

Salesforce Basics

Mastering Salesforce APIs: Composite vs. Bulk API 2.0 vs. GraphQL

⚡ 1-Minute Summary The Salesforce platform offers specialized APIs for different workloads. The Composite API bundles multiple REST calls into a single trip. Bulk API 2.0 processes millions of records asynchronously. GraphQL allows front-end applications to query exact data fields to avoid over-fetching. Choosing the wrong API leads to poor performance and hitting governor limits. 💬 In plain words: Three power APIs for three different jobs: Composite API bundles several REST calls into one single trip (e.g., creating a parent and children in one POST). Bulk API 2.0 acts like a freight train, moving millions of rows as background jobs. GraphQL acts like a restaurant menu, letting the caller order exactly the fields it wants with no wasted data. 📌 Example: Need to create an Account + 3 Contacts + 1 Opportunity in ONE API round trip? Use a Composite request with allOrNone=true so it's an all-or-nothing transaction. ...
Read article
Topic Apex
Apex Development

How to Serialize SOQL Query Results to JSON in Salesforce Apex

Whenever you need to send internal Salesforce data to an external application, a middleware tool like MuleSoft, or a front-end framework, that data must be translated into a universal format. In modern web development, that format is JSON. Converting database records into text strings is a fundamental task for any Salesforce developer. In plain words: When you want to transform your Salesforce database query results into a structured text format that web applications can read, you use the built-in JSON.serialize() method in Apex. This converts complex sObjects into standard JSON strings instantly.
Read article
Lightning Web Components

How to Track IP Geolocation in Salesforce using LWC and Apex Callouts

Tracking user locations based on IP addresses is a frequent requirement for security auditing, fraud detection, and creating localized customer experiences inside Salesforce. While legacy systems relied heavily on Visualforce, modern Salesforce architecture dictates using Lightning Web Components (LWC) backed by an Apex REST callout to fetch and display this geographic data securely. In plain words: An LWC captures the IP address input by the user and passes it to an Apex class. The Apex class sends an HTTP request to an external geolocation API, receives a JSON package containing location details (like city, country, and time zone), parses it, and sends it back to the LWC to be displayed on the screen.
Read article
Salesforce Integration & APIs

Generating Salesforce Report in CSV and Uploading to SharePoint using Apex - A Comprehensive Guide

💬 In plain words: Exporting a Salesforce report to CSV and uploading it to SharePoint via Apex requires querying the Reports API, converting the tabular string into a binary Blob, and issuing an authenticated HTTP REST POST callout directly to the SharePoint REST endpoint. In today's digital age, efficient data management and sharing across platforms are crucial for businesses to thrive. Salesforce and SharePoint are two powerful tools that many organizations utilize to manage customer relationships and collaborate on documents. In this blog, we will provide a step-by-step guide along with full working code on how to generate a Salesforce report in CSV format and upload it to a SharePoint site using Apex, Salesforce's programming language.
Read article
Apex Development

Demystifying JSON.deserializeUntyped in Apex Salesforce with Code Examples

In plain words: When working with API responses in Salesforce, use JSON.deserialize(jsonString, YourClass.class) if you know the exact structure of the incoming data. This gives you a structured Apex object so you can access data easily (e.g., user.email ). Use JSON.deserializeUntyped(jsonString) if the data structure changes dynamically or you only need a few specific fields. This returns a generic Map or List, requiring you to cast values manually. Almost every Salesforce integration involves a common step: an external system sends you a JSON string, and you need to extract its values using Apex. Salesforce provides two primary methods to accomplish this. In this guide, we will break down both approaches with working examples, highlight common developer pitfalls, and give you a simple rule of thumb for choosing the right one.
Read article
Apex Development

Apex Full Code Examples for HTTPMock in Test Classes

💬 In plain words: JSON.deserializeUntyped parses raw JSON strings into flexible generic Apex maps ( Map<String, Object> ) or lists ( List<Object> )—eliminating the need to define predefined wrapper classes for dynamic third-party API payloads. In Salesforce development, working with JSON information is a common challenge when integrating with external systems or handling data in a flexible and dynamic way. Salesforce provides a powerful method called JSON.deserializeUntyped that allows developers to parse JSON strings into a manageable format. In this blog post, we'll explore the ins and outs of JSON.deserializeUntyped in Apex, understand its usage, and provide practical code examples to demonstrate its capabilities.
Read article
Apex Development

Apex Test Class Examples for @HttpPost Exposed WebService Class

💬 In plain words: Unit testing an Apex REST service marked with @HttpPost requires manually setting up RestContext.request and RestContext.response , populating URI parameters or request payloads, and executing positive and negative assertion tests against database state. In Salesforce, the Apex programming language allows you to create powerful web services exposed to external systems for seamless data integration. A common scenario involves using the @HttpPost annotation within a @RestResource class to accept incoming REST requests. In this post, we'll walk through writing effective test classes for an @HttpPost Apex REST web service, setting up RestContext , and handling positive and negative scenarios to achieve robust code coverage.
Read article
Salesforce Integration & APIs

Obtaining Access Token Using Refresh Token in Salesforce Apex

💬 In plain words: The OAuth 2.0 refresh token flow allows integrations to programmatically request a new, short-lived session access token from Salesforce without requiring interactive user re-authentication. OAuth 2.0 is a widely used authentication protocol that provides secure access to resources on behalf of a user or an application. In this blog post, we will walk through the process of configuring a Connected App in Salesforce, obtaining a refresh token, and using it to acquire an access token using Apex code.
Read article
Salesforce Security & Access

Unveiling the Power of Named Credentials in Salesforce with Comprehensive Code Examples

💬 In plain words: Named Credentials encapsulate target callout URLs and authentication parameters into declarative setup records. By referencing endpoints with the callout: protocol in Apex, you automatically eliminate hardcoded credentials and bypass explicit Remote Site Settings. Named Credentials are a powerful feature in Salesforce that allow you to securely authenticate and connect to external services and APIs without exposing sensitive information like usernames and passwords. In this blog post, we'll delve into the world of Named Credentials, understand their significance, and provide you with in-depth code examples to illustrate their implementation in various scenarios.
Read article
Topic Apex
Apex Development

@HttpPost web service in Salesforce

💬 In plain words: An @HttpPost Apex REST web service allows outside applications to send JSON data directly into Salesforce. The server parses the incoming request payload, processes the data, and sends back a structured JSON response. Building custom web services in Salesforce allows external systems to interact with your org seamlessly. Using the @RestResource annotation alongside @HttpPost , you can easily expose Apex classes as custom REST API endpoints to accept incoming JSON payloads and return dynamic responses.
Read article
Topic Apex
Apex Development

Access members using Json Object in Apex Salesforce

When working with APIs and external web services in Salesforce Apex, parsing JSON responses is a daily task. Apex provides two distinct ways to deserialize JSON data into accessible properties: Typed Deserialization using a Wrapper Class and Untyped Deserialization using Maps.
Read article
Topic LWC
Lightning Web Components

How to Build a Real-Time Weather App in LWC Using External APIs

Connecting Salesforce Lightning Web Components (LWC) with external web services allows you to pull live third-party data directly into your user interface. In this step-by-step tutorial, we will build a dynamic weather component in LWC that fetches live weather forecasts based on user-entered locations using JavaScript's native fetch() API. In plain words: An LWC Weather Component takes a city or location name from an input box, sends an HTTP request to an external weather REST API, and presents live metrics like temperature and sky conditions right on the page.
Read article
Topic LWC
Lightning Web Components

How to Invoke Salesforce Tooling APIs and External REST APIs in LWC

In modern Salesforce development, Lightning Web Components (LWC) provide a fast and modular architecture for constructing rich user interfaces. Beyond rendering standard platform records, developers frequently need to query platform metadata via the Salesforce Tooling API or connect to external web services directly from client-side LWC controllers or supporting Apex adapters. In plain words: Invoking Tooling or external REST APIs from an LWC allows your UI to retrieve platform metadata (such as Apex class details or custom field definitions) or fetch data from third-party services in real time.
Read article
Topic Integration & APIs
Salesforce Integration & APIs

EST vs SOAP in Salesforce: Complete Integration Guide and Architecture Breakdown

In plain words: REST is like sending a postcard (lightweight, JSON-formatted, quick to read), while SOAP is like sending a registered, tamper-evident envelope with a legal contract inside (strictly typed, XML-only, highly regulated). Salesforce supports both to let you connect any external system. Salesforce integrations rely on communication protocols that determine how external applications talk to your CRM data. While modern architectures favor lightweight, mobile-ready interfaces, legacy enterprise architectures demand strict contracts and strict data governance. The two primary protocols fulfilling these needs are REST (Representational State Transfer) and SOAP (Simple Object Access Protocol) .
Read article
Topic LWC
Lightning Web Components

Integrating External Services with Salesforce Lightning Web Components (LWC)

In plain words: Integrating external services in Salesforce Lightning Web Components (LWC) allows your custom UI to communicate with third-party APIs and legacy software. By leveraging secure Named Credentials and standard JavaScript fetch methods or Apex controllers, your components can pull live external data, process payloads, and update the user interface in real time. Modern enterprise applications rarely operate in isolation. Businesses frequently need to connect their Salesforce CRM with external web services, payment gateways, shipping providers, or custom microservices. Lightning Web Components (LWC) provide a secure, modular framework to interact with external APIs directly from the browser or through an intermediary Apex controller.
Read article
Topic Architecture & DevOps
Salesforce Architecture & DevOps

How to Fetch Records by List View ID in Salesforce Apex & REST API Guide

In plain words: Fetching records using a List View ID allows your custom Apex controllers, batch jobs, or Lightning Web Components to reuse the exact filtering, sorting, and visibility logic already configured by users in standard Salesforce List Views. Instead of hardcoding complex WHERE clauses, you pass the List View ID to native tools like StandardSetController or the Salesforce User Interface API to pull matching records automatically. Salesforce List Views allow business users and administrators to create custom data filters without writing code. However, developers often face challenges when trying to query those exact filtered records programmatically. Recreating complex user-configured filter logic manually inside dynamic SOQL creates maintenance overhead whenever a list view is modified. By programmatically binding to the List View ID or developer name, applications can dynamically inherit list view criteria.
Read article
Topic Integration & APIs
Salesforce Integration & APIs

How to Get a Salesforce Session ID: SOAP Login, OAuth 2.0 & Apex Methods

In plain words: A Salesforce Session ID (or OAuth access token) acts as a digital key that proves your identity to Salesforce. Once authenticated, external applications pass this token in the Authorization: Bearer <Session_ID> header to query database records, execute REST/SOAP APIs, or trigger automations without re-entering login credentials on every request. Connecting third-party platforms, microservices, or custom scripts to Salesforce requires a valid authentication token. Whether you are building an integration using legacy SOAP web services or modern REST APIs, obtaining a session ID is the first step. Below is a breakdown of how to retrieve session IDs using SOAP login requests, native Apex methods, and modern OAuth 2.0 standards.
Read article
Topic LWC
Lightning Web Components

Upload Files via Multipart/Form-Data in Salesforce Apex: HTTP Callout Guide

💬 In plain words: A multipart/form-data HTTP request is the standard way to send binary files (like PDFs or images) along with text parameters to an external server. In Salesforce, you can achieve this in two ways: via LWC directly from the browser (which is fast and avoids server limits), or via Apex (which is highly secure and perfect for system-to-system integrations). Integrating Salesforce with external document systems like AWS S3, Google Drive, or custom OCR APIs almost always requires uploading files. Standard JSON REST APIs break when handling raw binary data, so developers must use the multipart/form-data content type. However, building these requests requires specific techniques depending on whether you are working on the client-side (LWC) or the server-side (Apex).
Read article
Topic Integration & APIs
Salesforce Integration & APIs

How to Use JSON2Apex to Parse JSON in Salesforce Apex

In plain words: External systems (like Google, Stripe, or internal HR tools) talk to Salesforce using a text format called JSON. But Salesforce's backend language, Apex, prefers to work with structured Objects. JSON2Apex is a concept (and a popular community tool) that automatically writes the Apex "Wrapper Classes" needed to translate that raw JSON text into usable Salesforce objects. If you are building an integration in Salesforce, you will inevitably have to handle JSON data. Manually parsing through complex, nested JSON strings is tedious and error-prone. By generating Apex classes that perfectly mirror the JSON structure, you can deserialize the data in a single line of code. In this tutorial, we will walk through the exact steps to convert a raw JSON response into strongly-typed Apex classes and output the data.
Read article
Topic LWC
Lightning Web Components

How to Make External HTTP Callouts from Salesforce LWC

In plain words: When building modern web applications, you often need to talk to third-party services—like checking if a phone number is valid, looking up weather data, or processing payments via an external API. In Salesforce Lightning Web Components (LWC), because your code runs directly in the browser, you can use the standard JavaScript fetch() method to talk directly to external web services without needing to write backend Apex controller code! Traditionally in Salesforce, if you needed to make an HTTP request to an external server, you had to route the call through an Apex class using the Http and HttpRequest classes. While Apex callouts are still mandatory for secure server-to-server communications, Lightning Web Components run on modern browsers that natively support the standard JavaScript fetch() API. In this guide, we will walk through how to build a phone number verification component that queries an external REST API directly from your LWC contro...
Read article