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

Trigger on case object
HI All,
I am writing a trigger as below to update Case due date automtically while insert.
I don't why this trigger is not working.
however when i remove caselst.add(c); this works fine. Please help
trigger DueDate on Case (before insert) {
list<case> caselst = new list <case>();
for(Case c:trigger.new){
if(c.Date_Due__c==Null){
c.Date_Due__c = system.today() + 1;
}
caselst.add(c);
}
Insert caselst;
}
I am writing a trigger as below to update Case due date automtically while insert.
I don't why this trigger is not working.
however when i remove caselst.add(c); this works fine. Please help
trigger DueDate on Case (before insert) {
list<case> caselst = new list <case>();
for(Case c:trigger.new){
if(c.Date_Due__c==Null){
c.Date_Due__c = system.today() + 1;
}
caselst.add(c);
}
Insert caselst;
}
Greetings to you!
Please try the below code, I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
All Answers
Greetings to you!
Please try the below code, I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
As your Trigger is on Case before insert, you no need to use the insert caselst method. automatically system save will be called after before insert or before update. I hope this will help why it is working if you remove the insert caselst.
Thanks,
Narendar
I hope it helps you.
Kindly mark this as solved if the information was helpful. It will help to keep this community clean.
Regards,
Khan Anas
Please Use this code.