How to count the number of child records under a parent using Apex
Mike Arthur • 16 August 2017
No need for any counter, use a Set and an Aggregate query
No content of my own here, just a pointer to someone who really knows what he's talking about, Peter_sfdc, the mighty Peter Chittum, check out his reply here:
https://developer.salesforce.com/forums/?id=906F0000000AcdaIAC
(Of course, if you don't have a good reason to use Apex, you can always go with Flow, as explained by the equally mighty Mike Gill:
http://www.salesforceweek.ly/2015/02/how-to-create-roll-up-summaries-using-flow.html
http://www.salesforceweek.ly/2015/02/how-to-create-roll-up-summaries-using-flow-part-2.html
)
My Blog of Salesforce Stuff
'XHR Failed' error when trying to install VS Code extension
What is $A (dollar A) in Lightning Aura component framework? Is it a global variable? Where are the docs for $A?
What to do if you receive emails about expiring certificates