You need to sign in to do that
Don't have an account?
How can i set a value on a mapped record?
I have code that creates a mapping from a Lead record. if i want to set values back on the Lead record, how can i do this? The code i am using is below, however, nothing seems to happen. Is this line of code possible?
LeadtaskMap.get(tsk.whoid).Status = 'Contacted';
Any suggestions?
Thanks.
trigger LeadTrigger on Task (before insert, before update)
{
List<Id> leadIds=new List<Id>();
for(Task t:trigger.new)
{
if(t.Status=='Completed')
{
if(t.whoId != null && String.valueOf(t.whoId).startsWith('00Q')==TRUE) //check if the task is associated with a lead
{
leadIds.add(t.whoId);
}//if 2
}//if 1
}//for
map<id,Lead> LeadtaskMap = new map<id,Lead>([SELECT Id, Description, Status FROM Lead WHERE Id IN :leadIds AND IsConverted=FALSE]);
for(Task tsk:trigger.new)
{
if(LeadtaskMap.keyset().contains(tsk.whoid))
{
if(tsk.Status == 'Completed' && tsk.Subject == 'Make contact with Lead')
{
LeadtaskMap.get(tsk.whoid).Status = 'Contacted';
}
if(LeadtaskMap.get(tsk.whoid).Description == null && tsk.Status == 'Completed' && tsk.Subject == 'Qualify Opportuntity')
{
tsk.adderror('Task cannot be completed until the following fields have been populated: Description');
}
Else
{
LeadtaskMap.get(tsk.whoid).Status = 'Qualified';
}
}
}
}
Try adding this code as a last line of code in trigger:
http://amitsalesforce.blogspot.in/2014/11/dynamic-field-mapping-using-custom.html
Like below code you can do. Please let us know if this will help you
Thanks
Amit Chaudhary