You need to sign in to do that
Don't have an account?
James 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
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
if it matches then in loop it is increasing the count in leadcounterMap decimal value with particular lead id.