Sub topic 3
GraphQL, UI, Event, and Development APIs
This chapter assumes you understand HTTP, JSON, Salesforce objects, and basic SOQL. It focuses on choosing APIs by the shape and timing of the work.
GraphQL API for flexible reads
Salesforce GraphQL API lets a client request only the fields and related records it needs. A single query can replace several REST requests. This helps user interfaces avoid overfetching data and reduces round trips.
GraphQL is mainly a read API. Its schema describes available objects, fields, relationships, and filters. Use REST when you need straightforward record creation or updates. Use GraphQL when the main problem is assembling a precise, nested view of Salesforce data.
UI API and Connect REST API
UI API is designed for Salesforce-style user interfaces. It returns records together with metadata such as field labels, display types, layouts, picklist values, and permissions. A custom interface can use this information to behave consistently with Salesforce configuration.
Connect REST API focuses on user and collaboration features, including Chatter feeds, files, topics, and communities. These APIs carry presentation and user-context concerns that ordinary data APIs do not.
Event-driven integration
Event APIs let systems react to changes instead of repeatedly polling Salesforce.
- Platform Events carry business events that Apex or external systems publish.
- Change Data Capture, or CDC, publishes changes to supported records, including create, update, delete, and undelete events.
- Pub/Sub API provides a modern publish-and-subscribe interface for consuming and publishing these events.
Events improve responsiveness and reduce polling, but consumers must handle duplicates, ordering limits, reconnects, and replay positions.
Metadata API and Tooling API
Metadata API deploys and retrieves configuration such as custom objects, fields, flows, and permission sets. Deployments are commonly asynchronous, so clients must check their status and inspect component-level errors.
Tooling API supports development tools. It exposes information and operations for Apex, Lightning components, debug logs, tests, and other development artifacts. It is for inspecting or changing the development model, not ordinary business records.
Choosing the right API
| Requirement | Good starting choice |
|---|---|
| Small synchronous record operation | REST API |
| Large asynchronous load | Bulk API 2.0 |
| Flexible nested read | GraphQL API |
| Configuration deployment | Metadata API |
| React to record changes | CDC or Pub/Sub API |
Also consider authentication, API limits, retry behavior, latency, and whether the operation reads data, changes data, or changes Salesforce itself.
Exercise
A dashboard needs Account records, related Contacts, field labels, and picklist values in one screen. Which API is the best starting point?
Show answer
Use UI API when the dashboard needs Salesforce-aware interface metadata. Use GraphQL when the requirement is only a flexible nested data read.