function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Pankaj Sharma 53Pankaj Sharma 53 

Trigger instead roll up summary

I have a custom object Target__c(parent) and Lead(child) in lookup relationship i want to check no of lead in target then plz help. How should i do this. Leads are visible in related list of target but there is a field in target named as No of Lead i want to update this field by the no of record in related list.
srlawr uksrlawr uk
It is possible to do this using a trigger, but before I write up/explain that whole process, can I point you towards a brilliant app that facilitates "roll up summaries" over lookup relationships?

If you head here:

https://github.com/afawcett/declarative-lookup-rollup-summaries


and give the read-me a read, and then install the unmanaged (or managed, depending on your needs) app 

Production install link  (https://login.salesforce.com/?ec=302&startURL=%2Fpackaging%2FinstallPackage.apexp%3Fp0%3D04tb0000000cBgv)

Sanbox install link (https://test.salesforce.com/?ec=302&startURL=%2Fpackaging%2FinstallPackage.apexp%3Fp0%3D04tb0000000cBgv)

Once you learn how to use this tool, you will never fear lookup relationships (regarding roll ups) again.

If you really just want to write your own trigger to calculate this, just say so and I will talk you through that too (it should be noted, this app has brilliant test coverage AND it GENERATES THE TEST COVERAGE FOR YOUR NEW TRIGGER as well, as generating the trigger!)


 
Pankaj Sharma 53Pankaj Sharma 53
Ya I used it but it's not working properly.

 
srlawr uksrlawr uk
Thank you for the informative update ;)