Sub topic 13
Limits, Performance, and When Not to Use External Objects
This chapter assumes you can create an external data source, generate external objects with Validate and Sync, and write basic SOQL. It covers what live callouts cost you and how to decide whether to virtualize or copy.
Every read is a callout
An external object stores no rows in Salesforce. Each query, list view, record page, or related list sends a request to the external system and waits for the answer. Your user's page speed is therefore the external system's speed plus network time.
Limits to plan for
Salesforce enforces limits on external data. Exact numbers change between releases, so check the current Salesforce Connect limits documentation before sizing a design. The categories that matter are:
- Callouts per transaction. Apex and triggers that touch external objects count against callout limits, and the callouts are subject to timeouts.
- Rows per request. The external system or adapter may cap how many rows come back. A query that matches more rows than the cap returns only part of them, so use paging and selective filters.
- Hourly request allowances. Some adapters and external systems throttle requests. Heavy list-view use can exhaust the external system's own rate limits.
- Feature gaps. External objects do not support everything standard objects do, such as some reporting, sharing, and automation features. Test the specific feature you need.
Writing queries that perform
The external system does the work only if Salesforce can push the filter down to it. Follow these habits.
- Select only the fields you need. Each extra field makes the payload larger.
- Filter on fields the external system indexes.
- Always set a
LIMIT. - Avoid queries that need Salesforce to fetch everything and then filter locally.
SELECT ExternalId, Name__c, Price__c
FROM Product__x
WHERE Price__c > 100
ORDER BY Name__c
LIMIT 20This query is cheap because it asks for three fields and twenty rows. Removing the WHERE and LIMIT turns it into a request for the whole table.
Relationships add cost too. An external lookup or indirect lookup on a related list causes one more callout per list shown. A page with several external related lists can fire several requests on load.
Failure modes
- External system down. Pages and queries that depend on it fail or time out. Salesforce cannot serve a cached copy.
- Slow responses. Users see slow pages, and Apex that waits on callouts holds up the transaction.
- Credential expiry. If the named credential or external credential stops working, every query fails at once.
- Schema drift. If the external schema changes, run Validate and Sync again or fields will mismatch.
Virtualize or copy?
| Need | Better fit |
|---|---|
| Always-current data, rarely queried | External objects |
| Very large data set you cannot store | External objects |
| Heavy reporting and dashboards | Copy into Salesforce |
| Complex automation, sharing, or triggers on the data | Copy into Salesforce |
| Must work when the external system is offline | Copy into Salesforce |
| High-volume reads on the same records | Copy, or cache a subset |
A hybrid design is common. Keep a small, frequently used subset as real records and leave the bulk behind external objects.
Exercise
A team wants to run daily dashboards and a nightly Apex batch job over 5 million order records that live in an ERP system. They are considering external objects. What do you recommend and why?
Show answer
Copy the data into Salesforce, for example with an integration or ETL tool. Dashboards and batch jobs over millions of rows would produce many live callouts, hit callout and rate limits, and fail whenever the ERP is slow or offline. External objects fit better for occasional lookups of current data, not for bulk reporting or batch processing.