You need to sign in to do that
Don't have an account?
lalit kumar 11
how to copy the task field value as on the associated lead field
Hi there,
I am trying to run a trigger for a while with different patterns but not getting the results except errors.
One custom field(value_to_be_copied__c) is on lead and one custom field(copied_value__c ) is on task.
The condition is whenever a task related to a lead is created, the value of value_to_be_copied__c should be copied to copied_value__c.
First pattern is :-
trigger leadtasktrigger on Task (after insert) {
set<id> leid = new set<id>();
for(task ta :trigger.new){
if(string.valueof(ta.whoid).startsWith('OOQ'))
{
leid.add(ta.whoid);
}
}
for(lead le2 :[select id, (select id, subject, copied_value__c from task), value_to_be_copied__c from lead where id in :leid]){
le2.task.copied_value__c = le2.value_to_be_copied__c;
}
}
Error for the above code is
Error: Compile Error: Didn't understand relationship 'task' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 10 column 16
Second pattern is -
trigger leadtasktrigger on Task (after insert) {
set<id> taid = new set<id>();
list<task> taid1 = new list<task>();
for(task ta :trigger.new){
if(string.valueof(ta.whoid).startsWith('OOQ'))
{
taid.add(ta.id);
}
}
for(task ta1 : [select id, subject, copied_value__c, whoid from task where id in: taid]){
taid1.add(ta1);
}
for(task ta2 : taid){
ta2.copied_value__c = ta2.who.value_to_be_copied__c ;
}
}
Error: Compile Error: Invalid field value_to_be_copied__c for SObject Name at line 18 column 26.
Please help .. TIA..
I am trying to run a trigger for a while with different patterns but not getting the results except errors.
One custom field(value_to_be_copied__c) is on lead and one custom field(copied_value__c ) is on task.
The condition is whenever a task related to a lead is created, the value of value_to_be_copied__c should be copied to copied_value__c.
First pattern is :-
trigger leadtasktrigger on Task (after insert) {
set<id> leid = new set<id>();
for(task ta :trigger.new){
if(string.valueof(ta.whoid).startsWith('OOQ'))
{
leid.add(ta.whoid);
}
}
for(lead le2 :[select id, (select id, subject, copied_value__c from task), value_to_be_copied__c from lead where id in :leid]){
le2.task.copied_value__c = le2.value_to_be_copied__c;
}
}
Error for the above code is
Error: Compile Error: Didn't understand relationship 'task' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 10 column 16
Second pattern is -
trigger leadtasktrigger on Task (after insert) {
set<id> taid = new set<id>();
list<task> taid1 = new list<task>();
for(task ta :trigger.new){
if(string.valueof(ta.whoid).startsWith('OOQ'))
{
taid.add(ta.id);
}
}
for(task ta1 : [select id, subject, copied_value__c, whoid from task where id in: taid]){
taid1.add(ta1);
}
for(task ta2 : taid){
ta2.copied_value__c = ta2.who.value_to_be_copied__c ;
}
}
Error: Compile Error: Invalid field value_to_be_copied__c for SObject Name at line 18 column 26.
Please help .. TIA..
If you want to copy some field value or assigning some default value to the inserted/updated record always use BEFORE Trigger.
Here I have updated your trigger. Try this should work for you.
All Answers
If you want to copy some field value or assigning some default value to the inserted/updated record always use BEFORE Trigger.
Here I have updated your trigger. Try this should work for you.