• Dilip Kumar 285
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi all, 

I am having some problems with a trigger I have developed on a Task object. The idea is that if a Task is created and "Name" (WhoId) field is populated with a Lead, it will capture some fields from that Lead and store them on the Task. 

Now, when I have a Lead already in the system and manually create an Activity/Task from it everything works perfectly. Task is being created and fields on the Task are being populated with values from that Lead. But, we also have Marketo integrated with out SF. The way it works is as follows: when a certain score is reached by a Lead inside Marketo, that Lead is pushed into SF. And at the same time Task is being created on that Lead and also pushed into SF. And this is where I am having problems. I can see new Leads pushed into SF and Task being ceated for those Leads as well (all done by Marketo Integration usaer). But fields are not populated. 

Looking at the debug logs it does look to me that my trigger is being invoked, but no fields are populated. 

What am I missing? Any ideas. 
 
trigger Inquiry_Tracking on Task (after insert) {
    BypassTriggerUtility u = new BypassTriggerUtility(); 
    if (!u.isTriggerBypassed())     // custom setting we have to bypass triggers when doing mass update/insert
    { 
    
      Task[] TskIdNew = Trigger.new;  
      Task[] TskIdOld = Trigger.old;
      List <Task > myTskList = New List<Task >();
      List <Lead > FindLead = New List<Lead >();
      String MAN;
      String LR;
      String LHQS;
      
      InquiryClass INQ = new InquiryClass();    // the class where queries are ran
      
      myTskList =INQ.returnthistskid(trigger.new[0]);
      if(checkRecursive.runOnce()){
      for (Task TaskLoop :myTskList){
        FindLead = INQ.FindLead(TaskLoop.WhoId);
        if (TaskLoop.RecordTypeId == '012U0000000aTe4IAE' && TaskLoop.WhoId != NULL){  
            System.debug('Entered if');
            
                System.debug('FindLead zise is'+ FindLead.size());
                if (FindLead.size() != 0){
                    System.debug('Entered SIZE if');
                    MAN = FindLead[0].Last_Lead_Source__c;
                    System.debug('MAN = ' +MAN);
                    LR = FindLead[0].last_Lead_Source_Detail__c;
                    System.debug('LR ='+LR);
                    LHQS = FindLead[0].State;
                    System.debug('LHQS ='+LHQS );
                    TaskLoop.Marketing_Activity_Name__c = FindLead[0].Last_Lead_Source__c;
                    //TaskLoop.Last_Referrer__c = FindLead.last_Lead_Source_Detail__c;
                }
                
            TaskLoop.Marketing_Activity_Name__c =   MAN;
            TaskLoop.Last_Referrer__c = LR;
            TaskLoop.Lead_HQ_State__c = LHQS;
        }
        update myTskList;
        }
      }//FOR
    }
}
 
public with sharing class InquiryClass {
  
  Public Static List<Task> TskList= New List<Task>();
  List <Lead > FindLead = New List<Lead >();
  
  Public List<Task> returnthistskid (Task TskRec){
      TskList= [ Select id, RecordTypeId, WhatId, WhoId,   Marketing_Activity_Name__c, Last_Referrer__c, Offer_ID__c from Task WHERE Id =:TskRec.Id];
      return TskList;
    }
    
    Public List<Lead> FindLead (Id whoId){
        FindLead = [ Select id, Last_Lead_Source__c, last_Lead_Source_Detail__c, State from Lead where id =: whoId];
        return FindLead;
    }
}

Thank you in advance,
Art.