Here's the business case. I want to have a reportable field on a lead that displays the number of contacts for, say, a city field match. This value could be used in reports, dashboards, snapshots, etc. The challenge is that we will have 100k+ leads and growing (and same for contacts). The second challenge is that we need the data to be ideally real time, worst case scenario a nightly process.
I've considered a trigger on both contact and lead trigger. Contact trigger would update lead(s) if the city field changed (or record deleted, etc). Lead trigger would populate the initial value. Seems reasonably smart but I have a lot of concern re: performance/etc given data volumes. Can't have this break at the wrong time. :)
Another is a straight up separate app that uses the API to query (ie can query a report on contacts or just use soql), then post back to leads if the number is different. Problem here is the API usage impact as the calls will be substantial.
I have toyed with remoteaction JS stuff but there are issues with subqueries and I remain concerned regarding performance there.
What are the common best practices for querying one object and posting back to another unrelated object, in larger volumes of data?
Thanks!