function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bujjibujji 

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

Anu Raj.ax1269Anu Raj.ax1269

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

bujjibujji

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

Anu Raj.ax1269Anu Raj.ax1269

sorry please 

 

change :-

task t = new task();

to

 

task tsk = new task();

 

thanks

Anuraj

bujjibujji

can u please modify and send

Anu Raj.ax1269Anu Raj.ax1269

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;

}

 

bujjibujji

same error is coming did u check in ur system.

it worked

bujjibujji

and we are using before insert so no need to insert please check the code in ur system.

 

Anu Raj.ax1269Anu Raj.ax1269

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;

}

bujjibujji

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.

KRKKRK
Try this, it will help for you

trigger updateCallDisposition on Task (before insert) {
Map<Id, Contact> conMap = new Map<Id, Contact>();
Set<Id> conIds = new Set<Id>();
for(Task t:Trigger.new){
    conIds.add(t.whoId);
}
conMap = new Map<Id,Contact> ([select id, name, Con_Auto_Num__c from contact where Id in: conIds]);
for(Task t:Trigger.new){
    t.CallDisposition = conMap.get(t.whoId).Con_Auto_Num__c;
}