SOQL Selectivity: Avoiding Full Table Scans on Million-Row Objects
The article discusses the importance of SOQL selectivity in Salesforce, particularly when dealing with large data volumes. It highlights how non-selective queries can lead to significant performance issues, such as full table scans that drastically increase query execution time. The article also provides strategies for rewriting queries to improve selectivity and maintain performance as data grows.
- ▪A Salesforce org grew from 50,000 Cases to 5 million Cases over four years, causing performance issues with Apex code.
- ▪SOQL selectivity is crucial for performance, as non-selective queries can lead to full table scans and timeouts.
- ▪The article outlines patterns for non-selective queries and offers refactoring strategies to improve selectivity.
Opening excerpt (first ~120 words) tap to expand
try { if(localStorage) { let currentUser = localStorage.getItem('current_user'); if (currentUser) { currentUser = JSON.parse(currentUser); if (currentUser.id === 3948393) { document.getElementById('article-show-container').classList.add('current-user-is-article-author'); } } } } catch (e) { console.error(e); } SapotaCorp Posted on May 24 • Originally published at sapotacorp.vn SOQL Selectivity: Avoiding Full Table Scans on Million-Row Objects #apex A Salesforce org grew from 50,000 Cases to 5 million Cases over four years. Apex code that processed Cases used to complete in 200ms. The same code now takes 30 seconds when it completes at all; sometimes it times out. The team blames "the platform getting slower." The actual cause is almost always SOQL selectivity.
…
Excerpt limited to ~120 words for fair-use compliance. The full article is at DEV.to (Top).