Sub topic 11
UI API and Connect REST API for user-interface use cases
This chapter assumes you can authenticate with OAuth 2.0 and call the REST API, as covered in earlier chapters. It also assumes you know what page layouts and field-level security are.
What these APIs are for
Salesforce has two REST-style APIs built for people-facing screens. The standard REST API returns raw data. A custom UI needs more than data: labels, picklist values, which fields a user may edit, and which fields the layout shows.
- UI API returns records together with the metadata needed to draw them. It applies the user's layout, field-level security, and sharing rules.
- Connect REST API (also called Chatter REST API) covers social and collaboration features. Examples are feeds, comments, files, groups, Experience Cloud sites, and CMS content.
Both live under /services/data/vXX.X/. UI API paths start with /ui-api/, and Connect REST paths start with /connect/ or /chatter/.
UI API in practice
The most-used resource is /ui-api/records/{recordId}. You list the fields you want in the fields parameter, qualified by object name.
curl -G "https://MyDomain.my.salesforce.com/services/data/v60.0/ui-api/records/$ACCOUNT_ID" \
--data-urlencode "fields=Account.Name,Account.Industry" \
-H "Authorization: Bearer $ACCESS_TOKEN"Each field in the response has a raw value and a displayValue. The display value is formatted for the user, for example a localized date or a picklist label.
Other useful resources:
| Resource | Returns |
|---|---|
| `/ui-api/object-info/{objectApiName}` | Field labels, data types, picklist links, permissions |
| `/ui-api/layout/{objectApiName}` | The layout sections and fields for a record type |
| `/ui-api/record-ui/{recordIds}` | Record data, object info, and layout in one call |
| `/ui-api/list-ui/{objectApiName}/{listViewApiName}` | Records in a list view, with column definitions |
Lightning Web Components use UI API without you writing HTTP calls. The getRecord wire adapter calls it and caches the result.
import { LightningElement, api, wire } from 'lwc';
import { getRecord, getFieldValue } from 'lightning/uiRecordApi';
import NAME_FIELD from '@salesforce/schema/Account.Name';
export default class AccountName extends LightningElement {
@api recordId;
@wire(getRecord, { recordId: '$recordId', fields: [NAME_FIELD] })
account;
get name() {
return getFieldValue(this.account.data, NAME_FIELD);
}
}Connect REST API in practice
Use Connect REST when the feature is social or content-oriented. A custom feed component, a file upload widget, or a mobile app that posts to Chatter fits here. The API returns feed items already shaped for display, including rich text segments, mentions, and capabilities such as likes.
flowchart TDThe diagram below shows how to pick between them.
Common errors
- Requesting fields the user cannot see. UI API leaves out or rejects fields blocked by field-level security. Test with a real user profile, not only an admin.
- Using UI API for bulk work. It returns metadata with every response and is tuned for single screens. Use REST or Bulk API 2.0 for integrations.
- Writing without metadata checks. UI API enforces validation and layout rules on save. Treat an error response as user feedback, not as a transport failure.
- Expecting full SOQL power. UI API does not run arbitrary queries. Use GraphQL API or REST for flexible reads.
Exercise
A team is building a mobile app that shows an Account detail page with the user's page layout and lets the user edit fields they have permission to change. Which API fits best, and why would plain REST API be a weaker choice?
Show answer
UI API fits best. It returns record data with layout, labels, and field-level permissions in one response, so the app does not have to rebuild that metadata. Plain REST API returns raw field values only, so the app would need extra calls and its own logic to learn layouts and permissions.