You need to sign in to do that
Don't have an account?
Regarding Trigger
Hi Guys,
I have a requirement like this,
I have a custom field which is autogenerated no in contacts object.If i add task to particular contact than i have a
custom field in task object which should be updated with the custom field value of contact(auto generated no).
conclusion, auto generated no should be in my task object custom field.
I wrote a trigger called before insert.
trigger task_feild_update on Task (before insert)
{
Contact con = new Contact();
con = [select id,Name,Languages__c
from Contact
where id =: Trigger.new[0].Who.Id];
system.debug('*************'+con);
Task t = new Task();
t.CustomFeild__c = con.Languages__c;
}
but data is not updating can anybody tell me how to solve it.
It is very urgent.
Thanks In Advance,
Bujji
please try this
trigger task_feild_update on Task (after insert)
{
set<id> tID = new set<id>();
//set<string> ISrg = new set<string>();
list<Contact> con = new List<Contact>();
list<Task> tLst = new List<Task>();
if(Task t:Trigger.new )
{
tID.add(t.id);
//tSrg.add(t.CustomFeild__c);
}
con = [select id,Name,Languages__c from Contact where id in :tID ];
for (integer i = 0; i <con.size(); i++)
{
Task t = new Task();
t.CustomFeild__c = con[i].Languages__c;
tLst.add(t);
}
insert tLst;
}
Thanks
Anuraj
i copied the code and try to save
i am getting this error
Error: Compile Error: expecting a right parentheses, found 't' at line 11 column 9
can u tell me plz
sorry please
change :-
task t = new task();
to
task tsk = new task();
thanks
Anuraj
can u please modify and send
trigger task_feild_update on Task (after insert)
{
set<id> tID = new set<id>();
//set<string> ISrg = new set<string>();
list<Contact> con = new List<Contact>();
list<Task> tLst = new List<Task>();
for(Task t:Trigger.new )
{
tID.add(t.id);
//tSrg.add(t.CustomFeild__c);
}
con = [select id,Name,Languages__c from Contact where id in :tID ];
for (integer i = 0; i <con.size(); i++)
{
Task tsk = new Task();
tsk.CustomFeild__c = con[i].Languages__c;
tLst.add(tsk);
}
insert tLst;
}
same error is coming did u check in ur system.
it worked
and we are using before insert so no need to insert please check the code in ur system.
Try this
trigger task_feild_update on Task (after insert)
{
set<id> tID = new set<id>();
//set<string> ISrg = new set<string>();
list<Contact> con = new List<Contact>();
list<Task> tLst = new List<Task>();
for(Task t:Trigger.new )
{
tID.add(t.id);
//tSrg.add(t.CustomFeild__c);
}
con = [select id,Name,Languages__c from Contact where id in :tID ];
for (integer i = 0; i <con.size(); i++)
{
Task tsk = new Task();
tsk.CustomFeild__c = con[i].Languages__c;
tLst.add(tsk);
}
insert tLst;
}
it is saved succesfully but while adding task the feild is not updated.
Can u change this code to after insert.Please send me a invite to gmail bajidssk@gmail.com.
so that i can chat instantly.