You need to sign in to do that
Don't have an account?
chandan kumar 99
SELF_REFERENCE_FROM_TRIGGER
Hi Gurus,
I have a trigger on Task object and I am trying to before insert and update a field Task object. I am getting following error message:
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger WeekendTasks caused an unexpected exception, contact your administrator: WeekendTasks: execution of BeforeUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 00T7F00000G5ulOUAR; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 00T7F00000G5ulO) is currently in trigger WeekendTasks, therefore it cannot recursively update itself: []: Trigger.WeekendTasks: line 15, column 1
Here is my trigger
trigger WeekendTasks on Task (before insert,Before update) {
list<Task> Tasweek =new List<Task>();
for(Task tweek:Trigger.new){
if(tweek.Subject != null) {
Date origin = Date.newInstance(1900,1,6);
Date due = tweek.ActivityDate;
Integer x = origin.daysBetween(due);
Integer day = Math.mod(x,7);
if (day < 2 ) {
Task tas = new Task (Id = tweek.Id,ActivityDate = (tweek.ActivityDate + 2));
Tasweek.add(tas);
}
}
}
update Tasweek;
}
I have a trigger on Task object and I am trying to before insert and update a field Task object. I am getting following error message:
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger WeekendTasks caused an unexpected exception, contact your administrator: WeekendTasks: execution of BeforeUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 00T7F00000G5ulOUAR; first error: SELF_REFERENCE_FROM_TRIGGER, Object (id = 00T7F00000G5ulO) is currently in trigger WeekendTasks, therefore it cannot recursively update itself: []: Trigger.WeekendTasks: line 15, column 1
Here is my trigger
trigger WeekendTasks on Task (before insert,Before update) {
list<Task> Tasweek =new List<Task>();
for(Task tweek:Trigger.new){
if(tweek.Subject != null) {
Date origin = Date.newInstance(1900,1,6);
Date due = tweek.ActivityDate;
Integer x = origin.daysBetween(due);
Integer day = Math.mod(x,7);
if (day < 2 ) {
Task tas = new Task (Id = tweek.Id,ActivityDate = (tweek.ActivityDate + 2));
Tasweek.add(tas);
}
}
}
update Tasweek;
}
Try below code
trigger WeekendTasks on Task (before insert,Before update) {
list<Task> Tasweek =new List<Task>();
for(Task tweek:Trigger.new){
if(tweek.Subject != null) {
Date origin = Date.newInstance(1900,1,6);
Date due = tweek.ActivityDate;
Integer x = origin.daysBetween(due);
Integer day = Math.mod(x,7);
if (day < 2 ) {
tweek.ActivityDate = tweek.ActivityDate + 2;
}
}
}
}
Thanks
Arpit
All Answers
Try below code
trigger WeekendTasks on Task (before insert,Before update) {
list<Task> Tasweek =new List<Task>();
for(Task tweek:Trigger.new){
if(tweek.Subject != null) {
Date origin = Date.newInstance(1900,1,6);
Date due = tweek.ActivityDate;
Integer x = origin.daysBetween(due);
Integer day = Math.mod(x,7);
if (day < 2 ) {
tweek.ActivityDate = tweek.ActivityDate + 2;
}
}
}
}
Thanks
Arpit
Thanks this code is running but
list <task> Taskweek = new List<Task>();
no any data store on task so overall Trigger is running fine