You need to sign in to do that
Don't have an account?
Seanno
Task field update
Hello,
Having a problem updating a custom field in a Task. I created a field called Time Zone, that I want to update with the field Time Zone from a Lead, when created or edited. When I try and write a formula, I get an error that the field Lead does not exist. Here's my formula. It works with the Account Field "Time Zone", but not the Lead Field. Please help.
if (Id <> null, {!Lead.Time_Zone__c}, {!Lead.Time_Zone__c})
Thank you.
There's no Lead field on Task. Instead there's a field called WhoId. This is because Task can be related to either a Contact or a Lead (as well as Account/Opportunity). If you'd like to read more, check out:
http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_relationships.htm#soql_polymorph_keys
The short story is you can't access fields in Lead from Task in formula fields.
You can update a field in task through trigger.
The sample code is for updating the description field of task on creating a new task using values in address field of the lead object.
trigger CopyLeadInformation on Task (before insert)
{
list<id> WhoIds = new list<id>();
for (Task t : trigger.new)
WhoIds.add(t.WhoId);
list<Lead> leadList = [select id,Company,Street,State,City,Phone,PostalCode from Lead where id in :WhoIds];
map<id, Lead> leadMap = new map<id, Lead>();
for(Lead l : leadList)
leadMap.put(l.id, l);
for (Task tsk : trigger.new)
{
system.debug('############3');
if (leadMap.containsKey(tsk.Whoid))
{
Lead l = leadMap.get(tsk.Whoid);
system.debug('>>>>>>>>>>' +l.id);
tsk.Description = tsk.Description + '\n'+ l.Company + '\n' + l.Street +'\n'+
l.City + ', ' + l.State + ' ' + l.PostalCode + '\n' + l.Phone;
system.debug('>>>>>>>>>>' + tsk.Description);
}
}
}
Hope this helps.