Working on my bundle-functionality for the CPQ app I need to get Info about three related objects to build my bundle: Product2, PricebookEntry and Configured_Product__c.
I could achieve that using 2-3 Queries and a bunch of Loops and Maps. I’m a huge fan of avoiding maps by using subqueries instead.
Advantages of subqueries:
1) Build in Null-Check
2) Only counts as one SOQL Querry
3) Way faster
Once I got used to Sub-Querries I could reduce the number of maps I use dramatically. Subqueries takes a little getting used to, but I think the extra effort pays off in terms of performance and limits.
The image shows the query which was enough to get all bundled products with configuration and price. No Map necessary.