You need to sign in to do that
Don't have an account?
raji devi 1
Trigger to create task on contact object
I am not getting any error on opportunity object and created task,but the same code is not working on contact
it giving error like this
exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Related To ID: id value of incorrect type: 0032800000NuHm0AAF: [WhatId]: T
Thanks in advance , Please give me solution for this
trgger autocreatetask on Contact (after insert , after update) {
list<task> tasklist = new list<task>();
for(contact con : trigger.new){
task t = new task();
t.whatid=con.id;
t.Status = 'In Progress';
t.Subject='call';
t.Priority = 'High';
t.ownerid= con.ownerid;
tasklist.add(t);
}
insert tasklist ;
}
it giving error like this
exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Related To ID: id value of incorrect type: 0032800000NuHm0AAF: [WhatId]: T
Thanks in advance , Please give me solution for this
trgger autocreatetask on Contact (after insert , after update) {
list<task> tasklist = new list<task>();
for(contact con : trigger.new){
task t = new task();
t.whatid=con.id;
t.Status = 'In Progress';
t.Subject='call';
t.Priority = 'High';
t.ownerid= con.ownerid;
tasklist.add(t);
}
insert tasklist ;
}
Try with below code ,I don't think it is required for after update .
Let me know if it helps!!
Thanks
Manoj
All Answers
Replace "whatId" with "whoId" and Check.
Kind Regards,
Sourav.
WhatId=WhatId represents nonhuman objects such as accounts, opportunities, campaigns, cases, or custom objects.
WhoId =The WhoId represents a human such as a lead or a contact
Please refer following link for more info
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_task.htm
Try with below code ,I don't think it is required for after update .
Let me know if it helps!!
Thanks
Manoj
Thanks All, Every thing is useful for me.
Regards,
Raji
exm : if we are going to remove email field in contact automatically email task also remove.
trigger autocreatetask on Contact (after insert, after update) {
list<task> tasklist = new list<task>();
if(trigger.isinsert && trigger.isafter){
for(Contact con : trigger.new){
//add logic for task if phone give task is created as call and email given to cretated email task
task t = new task();
if(con.phone!=null){
t.whoid=con.id;
t.ownerid= con.ownerid;
t.status = 'In Progress';
t.Priority = 'High';
t.subject= 'call';
tasklist.add(t);
}
if(con.email!=null){
task t2 = new task();
t2.whoid=con.id;
t2.ownerid= con.ownerid;
t2.status = 'In Progress';
t2.Priority = 'High';
t2.subject= 'email';
tasklist.add(t2);
}
}
}
insert tasklist ;
}