Salesforce customers working with large volumes of retained data in Privacy Center can encounter slow query performance, timeouts, or failures when attempting to access the data. This issue is caused by a performance limitation when querying retention-backed external objects that use non-optimized fields, such as relationship (lookup) fields.
This issue is particularly visible when Related Lists are used to display retained data, because system-generated queries often scan large volumes of data and time out before loading. This article provides a two-phase SOQL (Salesforce Object Query Language) workaround to access the data more efficiently.
Note: Execute the queries with a tool such as Workbench or the Developer Console.
Why Single Queries Fail on High-Volume Privacy Center Data
A single query that uses a non-indexed lookup field to filter a large volume of retained records may fail to return results because it attempts to scan the entire retention store. For example, querying SELECT FIELDS(ALL) FROM [RetentionObject]_x WHERE [LookupField]_c = 'value' can time out when the retention store contains a large number of records.
The two-phase query approach solves the performance problem by splitting one slow query into two faster queries. In Phase 1, you run a lightweight query that uses your filter condition to retrieve only the record IDs that match. Because this query only returns IDs (not all fields), it runs faster even against large data volumes. In Phase 2, you take those record IDs and run a second query that uses the optimized Id_c field (which is indexed) in an IN clause to retrieve the full record data efficiently. This avoids the performance issue caused by querying large volumes of data using non-optimized relationship fields in a single query.
The first query uses the desired filter to find a limited set of record IDs. Copy the resulting Id_c values to use in Phase 2.
Query format: SELECT Id_c FROM [RetentionObject]_x WHERE [LookupField]_c = 'value' LIMIT 200
Replace [RetentionObject]_x with your retention object API name and [LookupField]_c with the lookup field name you are filtering on.
The second query takes the Id_c values from Phase 1 and uses them in an IN clause. Because Id_c is an optimized (indexed) field, this query executes efficiently and retrieves all fields for the matching records.
Query format: SELECT FIELDS(ALL) FROM [RetentionObject]_x WHERE Id_c IN ('id1', 'id2', 'id3', ...) LIMIT 200
Replace the id1, id2, id3 placeholders with the actual Id_c values returned from Phase 1.
If you continue to experience timeouts after implementing the two-phase SOQL query, contact Salesforce Customer Support to request compaction of your retention store data. Compacting data can improve query performance and reduce the risk of timeouts.
005237174

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.