Back to LinkedIn posts

LinkedIn post 99

This article "How to calculate Salesforce field utilization with Node.js" by Pablo...

This article "How to calculate Salesforce field utilization with Node.js" by Pablo Gonzalez ๐Ÿ‡จ๐Ÿ‡ท has inspired me to explore another way to estimate field utilization.

๐Ÿ”— LINK: https://lnkd.in/grkRxqfP

In one client org, all COUNT queries on the Case object were timing out. Since we only needed estimates, the workaround was to request the query plan and use the cardinality estimates instead of exact counts.

The first two screenshots show how to enable the Query Plan button in the Developer Console.

In the article, utilization is calculated as:
๐Ÿ‘‰ query count of records where field != null
๐Ÿ‘‰ divided by total record count

My alternative approach (faster but less precise):
๐Ÿ‘‰ request the query plan for
SELECT count(Id) FROM Object WHERE Field != null
๐Ÿ‘‰ extract:
cardinality (estimated rows matching predicate)
SObject cardinality (estimated total rows)
๐Ÿ‘‰ Utilization โ‰ˆ cardinality / SObject cardinality

In my tests, estimates deviated from actual counts by less than 2 percent.

This can be automated to run on each field using the Tooling API (response shown in the 3rd screenshot):
โš™๏ธ /services/data/v62.0/tooling/query/?explain=QUERY

This gives a fast signal on whether a field is mostly populated or mostly blank. It does not work for long text fields, but Pablo's article covers a workaround.

Additional considerations:
๐Ÿ”Ž Ideally we should get a distinct count of the values on a field - it might be useful to see if a value is dominating. Required fields won't have nulls but the users might be populating it with a placeholder just to save the record.
๐Ÿ”Ž We should also get counts over time - a field might have been just added so a small percentage of records have it populated. Or maybe a field was migrated from other system and/or is no longer populated.

Query plan cardinality is not a replacement for exact counts, but it is cheap and scalable proxy that can give a preliminary distribution insight.

This article "How to calculate Salesforce field utilization with Node.js" by Pablo...
This article "How to calculate Salesforce field utilization with Node.js" by Pablo...
This article "How to calculate Salesforce field utilization with Node.js" by Pablo...