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
Saravanan Sivalingam 1Saravanan Sivalingam 1 

Roll-up counts in look up related objects in Apex, its not working....what is the mistake, any suggestions..

Master__c(Parent Object)
child1__c (Child Object).
Child1_count__c(Roll up summary field/Custom Field).
c.MD1__c(Lookup field).

trigger RollupChild on child1__c (after insert,after delete, after undelete) {
    
    List<id> master = new List<id>();
    if(Trigger.isInsert || Trigger.isUndelete)
    {
        For(child1__c c : Trigger.new)
        {             
            master.add(c.MD1__c);                     
             }
    }
    if(Trigger.isDelete)
    {
         For(Child1__c c : Trigger.old)
         {
            master.add(c.MD1__c);
        }
    }
    List<Master__c> mas = new List<Master__c>();
    For(Master__c m : [SELECT Child1_count__c FROM Master__c WHERE id =: master])
    {
        m.Child1_count__c = m.Child1_count__c+1;
        mas.add(m);
    }
    
        update mas;
    
}