You need to sign in to do that
Don't have an account?
sfdcianp
Trigger on task
i have a relation with account and contact.Account record is having the contact name as a field.
Whenever a new task is created with related to an account i need to equate the contact field on account to the new custom field in the task obj.
COuld any one help me in this scenario..
Thanks in advance
Try this
trigger PopulateContactOnTask on Task(before insert){
List<Id> lstid = new List<Id>()[
for(task t : Trigger.new){
if(t.WhatId.startsWith('001') != NULL){
lstid.add(t.WhatId);
}
}
Map<id,account> aMap = new Map<id,account>([Select Id,Contactname__c from Account where id in :lstid]);
for(task t : Trigger.new){
if(t.WhatId.startsWith('001') != NULL){
t.taskcontact__c = aMap.get(t.WhatId).Contactname__c;
}
}
}
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks