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
aaryan sriaaryan sri 

capture latest lead status on task record

Hi All,
Disposition creation on lead record we are creating a task record for that. I wrote a logic on task trigger to capture lead status while task record creating. On task records creation we are capturing lead memberid, date and status from associated lead. Issue is task record lead status field is not matching with current lead status. Lead status is updating after task record creates task record, so task record lead status is not matching with current lead status. Please help me out how to match task lead status with current lead status.
below is the code logic written on Task tirgger handler 

 Map<id,Lead> mapLead = new Map<id,Lead>([SELECT ID,Name,CompName_HF__c, Membbno_HF__c,Recertdate_HF__c,Status FROM Lead Where id IN:lstLeadId]);
          for(Task objTask : lstNewTaskMap)
                    System.debug(' Entered into Lead loop' );
                    if(objTask.Subject <> NULL && objTask.Subject.contains('Call') && objTask.Status=='Completed')
                     System.debug(' Entered into Task Type loop' );
                      if(objTask.whoid==null) continue;
                if(mapLead.get(objTask.whoid)==null) continue;
                if(objTask.WhoId <> NULL && objTask.WhoId.getSobjectType() == Lead.getSObjectType())
                  Lead objLead = mapLead.get(objTask.whoid);
                      system.debug('***** objLead '+ objLead);
                        if(objTask.Type != null && objTask.Type.contains('Call'))
                              system.debug('objLead.Membbno' + objLead.Membbno_HF__c);
                              system.debug('objTask.LeadMemberId' + objTask.Lead_MemberId_HF__c);
                              system.debug('objTask.LeadStatus' + objTask.Lead_Status_HF__c);

aaryan sriaaryan sri
Can we make any config changes to achive issue or need code changes?