You need to sign in to do that
Don't have an account?

Please solve this error
Error:Apex trigger TaskToCommunityTrigger caused an unexpected exception, contact your administrator: TaskToCommunityTrigger: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []: Class.TaskToCommunity.aftrupdate: line 27, column 1
=======================================================================
public class TaskToCommunity {
public static void aftrupdate(Map<id,contact> oldmap,Map<id,Contact> newmap){
list<Task> ta=new list<Task>();
user u=[select id from user where alias='sree'];
// profile p=[select id from profile where name='Partner Community User'];
for(id key:oldmap.keyset()){
Contact old=oldmap.get(key);
Contact newmp=newmap.get(key);
if(old.Phone!=newmp.Phone){
Task t=new Task();
t.OwnerId=u.id;
// t.OwnerId=p.id;
//t.OwnerId=userinfo.getUserId();
t.Status='Pending';
t.Priority='Normal';
//t.WhatId=newmp.id;
t.ActivityDate=system.today();
t.Subject='Testing';
ta.add(t);
}
}
update ta;
}
}
===============================================================================================
trigger TaskToCommunityTrigger on Contact (after update) {
if(trigger.isafter && trigger.isupdate){
TaskToCommunity.aftrupdate(Trigger.oldmap, Trigger.newmap);
}
}
=======================================================================
public class TaskToCommunity {
public static void aftrupdate(Map<id,contact> oldmap,Map<id,Contact> newmap){
list<Task> ta=new list<Task>();
user u=[select id from user where alias='sree'];
// profile p=[select id from profile where name='Partner Community User'];
for(id key:oldmap.keyset()){
Contact old=oldmap.get(key);
Contact newmp=newmap.get(key);
if(old.Phone!=newmp.Phone){
Task t=new Task();
t.OwnerId=u.id;
// t.OwnerId=p.id;
//t.OwnerId=userinfo.getUserId();
t.Status='Pending';
t.Priority='Normal';
//t.WhatId=newmp.id;
t.ActivityDate=system.today();
t.Subject='Testing';
ta.add(t);
}
}
update ta;
}
}
===============================================================================================
trigger TaskToCommunityTrigger on Contact (after update) {
if(trigger.isafter && trigger.isupdate){
TaskToCommunity.aftrupdate(Trigger.oldmap, Trigger.newmap);
}
}
try this one :
public class TaskToCommunity {
public static void aftrupdate(Map<id,contact> oldmap,Map<id,Contact> newmap){
list<Task> ta=new list<Task>();
user u=[select id from user where alias='sree'];
// profile p=[select id from profile where name='Partner Community User'];
for(id key:oldmap.keyset()){
Contact old=oldmap.get(key);
Contact newmp=newmap.get(key);
if(old.Phone!=newmp.Phone){
Task t=new Task();
t.OwnerId=u.id;
// t.OwnerId=p.id;
//t.OwnerId=userinfo.getUserId();
t.Status='Pending';
t.Priority='Normal';
//t.WhatId=newmp.id;
t.ActivityDate=system.today();
t.Subject='Testing';
ta.add(t);
}
}
insert ta;
}
}
Thanks let us know if it helps you
You are getting this error because a new list of task records is created and you are updating it. To use 'update' statement you should query the older task records, update any field in it, then use update statement.
For now, I have used SOQL query inside the for loop (to avoid any other confusion), but it is not a recommended practice so you should create a map of tasks after querying all the required task records. I am not very clear with your requirement if you could elaborate 'My requirement is whenever contact phone is updated then assign to the partner user' then I may provide you with the exact solution.
Hope my answer helps.
If you have any confusion or need any clarification or have some other requirement please reply to this message.
Shubham Nandwana.
AppPerfect Corp.
salesforce@appperfect.com
408-252-4100
http://www.appperfect.com/services/salesforce/
Salesforce Development & Operations Experts