You need to sign in to do that
Don't have an account?
Trigger to update task field from lead field
I'm just learning triggers and have a relatively simple goal. When a new task is created I need to copy the contents of a custom field on the Lead object and put it in a custom field on the Task object.
I've been reading here for about 4 hours and the triggers proposed are significantly more complex. However, based on my reading here is a trigger that I assembled. Note that lead.type__c is the source field and task.account_type__c is the destination field.
trigger UpdateAccountType on Task (after update) {
Set<Id> leadIds=new Set<Id>();
for(Task t : Trigger.new){
if(String.valueOf(t.whoId).startsWith('00Q')==TRUE){ //check if the task is associated with a lead
if( !leadIds.contains(t.whoid)){
leadIds.add(t.whoId);
t.Account_Type__C = lead.Type__c;
}}}}
Can anyone help with this or, have I taken a wrong turn and need to start from stratch?
TIA
I've been reading here for about 4 hours and the triggers proposed are significantly more complex. However, based on my reading here is a trigger that I assembled. Note that lead.type__c is the source field and task.account_type__c is the destination field.
trigger UpdateAccountType on Task (after update) {
Set<Id> leadIds=new Set<Id>();
for(Task t : Trigger.new){
if(String.valueOf(t.whoId).startsWith('00Q')==TRUE){ //check if the task is associated with a lead
if( !leadIds.contains(t.whoid)){
leadIds.add(t.whoId);
t.Account_Type__C = lead.Type__c;
}}}}
Can anyone help with this or, have I taken a wrong turn and need to start from stratch?
TIA
All Answers
For example, to expose the State field from the Lead or Contact you might have formula field like:
If the Lead’s Contact lookup field is populated then the formula will display the field from the contact, else the field from the lead if that lookup is not blank.
No triggers. Just process builder + custom lookup fields + formula fields.
Doug Ayers
douglascayers.com