Sub topic 7
Reading a Record with GET
This chapter assumes you can already build a resource URL and send an authenticated request. It uses the SF_INSTANCE_URL, SF_ACCESS_TOKEN, and SF_API_VERSION variables from the earlier chapters. It also assumes you have an Account ID from the create step. You will see how a single-record GET works, how to control which fields come back, and how to handle the failures you are most likely to hit.
The request
Reading a record is a GET request to the sObject Rows resource. The URL is the sObject collection URL with the record ID appended:
/services/data/{version}/sobjects/{SObjectName}/{recordId}GET is safe and idempotent. It changes nothing in the org, so you can retry it freely after a network failure. A GET has no request body, so you do not need a Content-Type header. You only need the Authorization header.
The simplest call omits the fields parameter:
curl "$SF_INSTANCE_URL/services/data/$SF_API_VERSION/sobjects/Account/001xx000003DGb2AAG" \
-H "Authorization: Bearer $SF_ACCESS_TOKEN"Without fields, the API returns every field on the record that the authenticated user can see. For a standard object such as Account, that is dozens of fields, most of them null. The response is large and can include fields you did not know existed.
Limiting the response with `fields`
Pass the fields query parameter with a comma-separated list of field API names:
curl "$SF_INSTANCE_URL/services/data/$SF_API_VERSION/sobjects/Account/001xx000003DGb2AAG?fields=Name,Industry" \
-H "Authorization: Bearer $SF_ACCESS_TOKEN"A successful read returns status 200 OK and a JSON object like this:
{
"attributes": {
"type": "Account",
"url": "/services/data/v60.0/sobjects/Account/001xx000003DGb2AAG"
},
"Id": "001xx000003DGb2AAG",
"Name": "Acme Corp",
"Industry": "Technology"
}Three details are worth noting:
- The
attributesobject is metadata, not a field. It holds the sObject type and the relative URL of the record. Use it when you handle mixed record types, for example the results of several queries. Idcomes back even though you did not list it.- Field names are API names, not labels. Custom fields end in
__c, for exampleRegion__c. Names are not case sensitive in thefieldslist, but keep the exact casing to match your code and the describe output.
The values in the JSON use their natural types. Text is a string, a checkbox is true or false, and a number is a JSON number. A field with no value is null. Dates and datetimes are ISO 8601 strings, such as 2026-12-01T08:18:29.000+0000.
Request and response flow
The diagram shows the exchange for a read, including the common failure branches.
Reading in Python
The Python script from the earlier chapter performs the read like this, using params so that requests encodes the query string:
import os
import requests
instance_url = os.environ["SF_INSTANCE_URL"]
token = os.environ["SF_ACCESS_TOKEN"]
version = os.environ.get("SF_API_VERSION", "v60.0")
account_id = os.environ["SF_ACCOUNT_ID"]
base = f"{instance_url}/services/data/{version}"
headers = {"Authorization": f"Bearer {token}"}
response = requests.get(
f"{base}/sobjects/Account/{account_id}",
headers=headers,
params={"fields": "Name,Industry"},
timeout=30,
)
if not response.ok:
raise RuntimeError(f"{response.status_code}: {response.text}")
account = response.json()
print(account["Name"], account["Industry"])Set SF_ACCOUNT_ID to the id value from your create response before you run it. The timeout matters. Without it, requests can wait indefinitely on a stalled connection.
Choosing which fields to request
Naming fields is the main lever you control on a read. Consider these trade-offs:
| Approach | Response size | Behavior when a field is missing or hidden |
|---|---|---|
| No `fields` parameter | Large, all visible fields | Hidden fields are silently left out |
| `fields=Name,Industry` | Small, only what you ask for | A field the user cannot see or that does not exist causes an error |
The second row is the one that surprises people. If you ask for a field that does not exist, or one the user cannot read because of field-level security, the call fails rather than omitting it. That makes the explicit list stricter, which is usually what you want. A typo then fails loudly instead of leaving you with a missing key.
Prefer an explicit fields list in production code. It keeps payloads small, makes your code's data needs obvious, and means that new fields added to the object later do not change your responses.
Record IDs
Salesforce IDs come in two forms:
- The 15-character form is case sensitive. It is what you often see in the browser URL of the Lightning UI.
- The 18-character form adds a three-character case-insensitive checksum suffix. The API returns this form.
Both forms work in the URL. Use the 18-character form in code and in any system that might compare IDs case-insensitively, such as a spreadsheet or a database with a case-insensitive collation. Two different 15-character IDs can look identical when case is ignored.
The first three characters of an ID identify the object type. For example, 001 is an Account. A valid ID for the wrong object type, such as a Contact ID sent to the Account URL, does not return the record. Check that the object name in the URL matches the ID prefix when you debug a read that should work.
Conditional reads
If you poll a record to detect changes, you can avoid downloading unchanged data. Send an If-Modified-Since header containing an HTTP date:
curl -i "$SF_INSTANCE_URL/services/data/$SF_API_VERSION/sobjects/Account/001xx000003DGb2AAG?fields=Name,Industry" \
-H "Authorization: Bearer $SF_ACCESS_TOKEN" \
-H "If-Modified-Since: Tue, 01 Dec 2026 08:00:00 GMT"If the record has not changed since that time, the API returns 304 Not Modified with no body. Otherwise it returns 200 and the record. The -i flag prints the status line and headers so you can see which case you got. A related header, If-Unmodified-Since, is for the opposite check. It returns 412 Precondition Failed if the record has changed since the date you give.
Treat 304 as a success in your client. Many HTTP wrappers raise on any non-2xx code, which will break a conditional read unless you handle it.
Common failures
Salesforce returns errors as a JSON array of objects, each with message and errorCode. The next chapter covers error handling in depth. These are the ones you will meet on a read:
| Status | `errorCode` | Typical cause | Fix |
|---|---|---|---|
| 401 | `INVALID_SESSION_ID` | The access token has expired or was revoked | Get a new token, then retry the request |
| 404 | `NOT_FOUND` | The record was deleted, the ID is wrong, or the user cannot see it | Check the ID and the object name in the URL |
| 400 | `INVALID_FIELD` | A name in `fields` does not exist or is not visible | Fix the field name, or check field-level security |
| 400 | `MALFORMED_ID` | The value is not a valid Salesforce ID | Check for truncation or stray whitespace |
A body for a bad field looks like this:
[
{
"message": "\nSELECT Id, Name, Industyr FROM Account WHERE Id = '001xx000003DGb2AAG'\n ^\nERROR at Row:1:Column:24\nNo such column 'Industyr' on entity 'Account'. If you are attempting to use a custom field, be sure to append '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.",
"errorCode": "INVALID_FIELD"
}
]The API builds an internal query from your fields list, so the message shows a SELECT statement with a caret under the bad name. Read the "No such column" line to find the cause.
Note that 404 NOT_FOUND does not always mean the record is gone. Sharing rules can hide a record from the running user, and the API reports that the same way it reports a missing record. If the record exists in the UI but your integration gets a 404, compare the integration user's access with your own.
Reading versus querying
A single-record GET needs the record ID. If you do not have it, you need a different resource, the SOQL query endpoint, which later chapters cover. Choose between them like this:
- Use GET on the record URL when you hold the ID and want one record.
- Use a query when you search by field values, or need several records or related records in a single call.
- Do not loop over many GETs to read a list of IDs. Each call counts against your org's API request limit, and a single query or a Composite call is much cheaper.
Exercise
Your integration reads an Account with fields=Name,Region__c and receives 400 with INVALID_FIELD. The same call without a fields parameter returns 200 and does not include Region__c. What is the most likely cause, and how do you confirm it?
Show answer
The integration user most likely cannot see Region__c, because of field-level security. Without fields, the API silently leaves out fields the user cannot read, which explains the 200 without that key. With an explicit list, the hidden field causes an error. A typo in the field name would also cause INVALIDFIELD, so first check the spelling and the `_c` suffix against the describe output. If the name is correct, check the integration user's field-level security or permission sets for that field.
Exercise
You poll one Account every minute and want to avoid downloading the body when nothing has changed. Which header do you send, and which status code means "nothing changed"?
Show answer
Send If-Modified-Since with an HTTP date, for example Tue, 01 Dec 2026 08:00:00 GMT. A 304 Not Modified response with no body means the record has not changed since that time. Your client must treat 304 as a normal result and not as an error.