Skip to main content
Anant Pandey (HCLTech) が「#Apex」で質問
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;

  

}
6 件の回答
  1. 2019年3月27日 14:01
    Hi Anant,

    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.

     

    trigger UpdateCaseField on Case (before insert) {

    for(Case c : Trigger.new){

    if (c.Date_Due__c == Null) {

    c.Date_Due__c = System.today() + 1;

    }

    }

    }

    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