Sub topic 4
Objects, fields, and record IDs
This chapter assumes you can read JSON, know basic HTTP, and have an access token for a Salesforce org. It explains the data model that every REST call works against. Later chapters use it when they create, read, and update records.
Objects are tables, records are rows
Salesforce stores data in objects. In the REST API an object is called an sObject. Each sObject is like a table. Each record is one row in that table, and each field is a column.
Standard objects ship with Salesforce, such as Account, Contact, and Opportunity. Custom objects are created in your org, and their API names end in __c, for example Invoice__c.
The REST API addresses an object by its API name, not its label. The label is what users see in the UI. The API name is what you put in the URL. These can differ, so check the API name in Object Manager or with the describe resource covered in a later chapter.
Fields
Each field has an API name and a type. In JSON you use the API name as the key.
| Kind of field | Example API name | Notes |
|---|---|---|
| Standard field | `Name`, `Industry` | Defined by Salesforce |
| Custom field | `Region__c` | Ends in `__c` |
| Lookup relationship | `AccountId` | Holds the ID of a parent record |
| System field | `Id`, `CreatedDate` | Set by Salesforce |
Some fields cannot be written. Id, CreatedDate, and formula fields are read-only. If you send one in a POST or PATCH body, the API rejects the request. Other fields are required. Name is required on Account, so a create call without it fails with REQUIRED_FIELD_MISSING.
Field access also depends on the user behind the token. Field-level security can hide a field from one user and show it to another. The same query can therefore return different fields for different tokens.
Record IDs
Every record has a unique Id. Salesforce generates it when the record is created. You never choose it.
An ID comes in two forms:
- 15 characters, which is case-sensitive. This is the form shown in some UI URLs.
- 18 characters, which is case-insensitive. The last three characters are a checksum. The API returns this form.
The first three characters are a key prefix that identifies the object. For example, 001 means Account and 003 means Contact. The ID in the create response from the Topic Spine, 001xx000003DGb2AAG, starts with 001, so it is an Account.
Use the 18-character form in code. Comparing 15-character IDs as plain strings can give wrong results in case-insensitive systems such as spreadsheets.
def object_from_id(record_id: str) -> str:
prefixes = {"001": "Account", "003": "Contact", "006": "Opportunity"}
return prefixes.get(record_id[:3], "unknown")
print(object_from_id("001xx000003DGb2AAG")) # AccountPrefixes for custom objects differ between orgs, so do not hard-code them. This check is only a quick sanity test for standard objects.
How the pieces fit into a request
An sObject name and a record ID together form a resource URL:
/sobjects/Accountis the collection. You POST here to create a record./sobjects/Account/001xx000003DGb2AAGis one record. You GET or PATCH here.
Common mistakes
- Using the UI label instead of the API name.
Account Nameis a label, andNameis the API name. - Forgetting the
__csuffix on custom fields and objects. - Sending a read-only field in a write request.
- Treating an ID as a value you can invent. Only Salesforce generates IDs, except when you upsert by an external ID field, which a later chapter covers.
Exercise
You POST to /sobjects/Account and the response contains "id": "001xx000003DGb2AAG". Which object does the ID belong to, which characters tell you, and which URL do you use to read that record?
Show answer
It belongs to Account, because the first three characters, 001, are the Account key prefix. You read it with a GET on /services/data/<version>/sobjects/Account/001xx000003DGb2AAG, using your instance URL and API version.
Exercise
A PATCH body contains {"Name": "Acme", "CreatedDate": "2026-01-01T00:00:00Z"} and the request fails. What is the likely cause, and how do you fix it?
Show answer
CreatedDate is a read-only system field, so the API rejects it. Remove it from the body and send only writable fields, such as {"Name": "Acme"}.