Skip to main content
Anant Pandey (DotSolved) 님이 #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일 오후 2: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