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
James Roberts 32James Roberts 32 

Flow translation - Decimal TempCounter

Hello - I need some help translating some functionality from an Apex Trigger that has been added to my org previously by a developer. 
I've figured out most of the code, but I'm not sure what the Decimal TempCounter is and why it is used. 
Can anyone give me a line by line translation to layman's terms of the below code:

map<id,decimal> leadcounterMap = new  map<id,decimal>();
   
    Set<id> duplicateids = new Set<id>();
    
    for(Task t: (trigger.isinsert) ? trigger.New : trigger.old)
    {
        if(t.Whoid != null)
        {
            //Rollingup for Leads
            if(String.ValueOf(t.Whoid).startsWith('00Q'))
            {
                if(leadcounterMap.keyset().contains(t.Whoid))
                {
                    Decimal TempCounter = 0;
                    TempCounter = leadcounterMap.get(t.Whoid);
                    TempCounter++;
                    leadcounterMap.put(t.Whoid,TempCounter);
                }
                else
                {
                    Decimal TempCounter = 1;
                    leadcounterMap.put(t.Whoid,TempCounter);
                }
            }
 //rolling up leads activity count 
    for(Lead l : leads)
    {
        Lead TempLead = leadTaskMap.get(l.id);
                
        if(TempLead.No_Of_Activities__c == null)
            TempLead.No_Of_Activities__c = 0;
        
        if(Trigger.isInsert)
            TempLead.No_Of_Activities__c  += leadcounterMap.get(l.id);
        else if(Trigger.isDelete)
            TempLead.No_Of_Activities__c  -= leadcounterMap.get(l.id);
        
        leadstoUpdate.add(TempLead);
    }

Thanks!
James
SFDC Traning 6SFDC Traning 6
if(leadcounterMap.keyset().contains(t.Whoid)) from here I can see that it is checking if leadcounterMap is having a matching contact id(who id of task).
if it matches then in loop it is increasing the count in leadcounterMap decimal value with particular lead id.