• Zhenyu Zhang
  • NEWBIE
  • 10 Points
  • Member since 2015

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

I am new to Salesforce.

At the moment, I am trying to create a trigger.
In the code, there is one picklist in my lead, and then there is another exact same picklist in my task. When ther is log a call or new task coming in. The task's picklist value will be default to same as the lead's picklist value automacally.

However, the trigger that I created is not running. Is there anything wrong with what I did? Or I just made it too complicated?

Here is my trigger,
Trigger PrePopulateTaskPromoCode on Task (before insert) {
        
    List<Lead> leadsToUpdate = new List<Lead>();
    List<Task> tasks = new List<Task>();
    
    for (Task t : trigger.new) {
        if (String.valueOf(t.WhoId).substring(0,3) == '00Q') {
            Lead leadToLookup = [Select promo_code__c FROM Lead WHERE Id = :t.WhoId];
            String promoCode = leadToLookup.Promo_Code__c;
            t.Promo_Code__c = promoCode;
            tasks.add(t);
  
        }
    }
   // update tasks;
}


 
Hi Masters,

I am new to Salesforce.

At the moment, I am trying to create a trigger.
In the code, there is one picklist in my lead, and then there is another exact same picklist in my task. When ther is log a call or new task coming in. The task's picklist value will be default to same as the lead's picklist value automacally.

However, the trigger that I created is not running. Is there anything wrong with what I did? Or I just made it too complicated?

Here is my trigger,
Trigger PrePopulateTaskPromoCode on Task (before insert) {
        
    List<Lead> leadsToUpdate = new List<Lead>();
    List<Task> tasks = new List<Task>();
    
    for (Task t : trigger.new) {
        if (String.valueOf(t.WhoId).substring(0,3) == '00Q') {
            Lead leadToLookup = [Select promo_code__c FROM Lead WHERE Id = :t.WhoId];
            String promoCode = leadToLookup.Promo_Code__c;
            t.Promo_Code__c = promoCode;
            tasks.add(t);
  
        }
    }
   // update tasks;
}


 
Hi Masters,

I am new to Salesforce.

At the moment, I am trying to create a trigger.
In the code, there is one picklist in my lead, and then there is another exact same picklist in my task. When ther is log a call or new task coming in. The task's picklist value will be default to same as the lead's picklist value automacally.

However, the trigger that I created is not running. Is there anything wrong with what I did? Or I just made it too complicated?

Here is my trigger,
Trigger PrePopulateTaskPromoCode on Task (before insert) {
        
    List<Lead> leadsToUpdate = new List<Lead>();
    List<Task> tasks = new List<Task>();
    
    for (Task t : trigger.new) {
        if (String.valueOf(t.WhoId).substring(0,3) == '00Q') {
            Lead leadToLookup = [Select promo_code__c FROM Lead WHERE Id = :t.WhoId];
            String promoCode = leadToLookup.Promo_Code__c;
            t.Promo_Code__c = promoCode;
            tasks.add(t);
  
        }
    }
   // update tasks;
}