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
Mike DeMilleMike DeMille 

trigger to roll up records on object

Hi, 

I could use some help getting started creating a trigger to do the following:

On accounts object, I want to summarize accounts passing the following filters into an account field (num_of_customers)

type = customer
ARR > 0

I simply want the total number of accounts that fall under that criteria to display on the accounts object in the 'num_of_customers' field.  Anyone willing to help?
SalesFORCE_enFORCErSalesFORCE_enFORCEr
There is a free app which can do that
https://appexchange.salesforce.com/listingDetail?listingId=a0N3000000B45gWEAR
EldonEldon
Hi Mike,

What do you mean by ARR > 0 ?

 
Mike DeMilleMike DeMille
Eldon - thanks for the response.  ARR is just a currency field (custom field)
EldonEldon
Hey Mike sorry for the delay.You want to update all your accounts field num_of_customers with the total number of accounts that fall under that category everytime an update or insert is done right?
EldonEldon

The following trigger works though it is a temporary solution, Try something like below.( include your condition with the field ARR in the if condition)
 
trigger acctrgr2 on Account (after insert) {
    
    list<account> fullAcc= [select id,name,num_of_customers__c,type from account ];
    integer count = 0;
    for(account acc : fullAcc){
        if(acc.type=='Customer - Direct'){
            count++;
        }
    }
    
    for(account acc : fullAcc){
        acc.num_of_customers__c=count;
    }
    
    update fullAcc;
}

let me know if it works.

Regards