Hi Mohit ,
I am attaching a trigger to count no. of contacts on account (Roll up-action-count)
Trigger countContacts on Contact (after insert){
Set<Id> accIdset = new Set<Id>();
List<Account> accList = new List<Account>();
List<AggregateResult> arList = new List<AggregateResult>();
Map<String,Double> acmap = new Map<String,Double>();
//Added Account Id in Set
for (Contact con: Trigger.new){
accIdset.add(con.accountId);
}
// Query Contact Created
if(accIdset.size()>0){
arList = [select AccountId aid,Count(Id) i from Contact where AccountId IN :accIdset group by AccountId];
}
for(AggregateResult q : arList){
acmap.put((String)q.get(‘aid’),(Double)q.get(‘i’));
}
for (Account acc:[Select Id,Total_Count__c From Account Where Id in: accIdset]){
acc.Total_Count__c = acmap.get(acc.Id);
accList.add(acc);
}
update accList;
}