Skip to main content
I have written trigger on after update for case creation. there is recordtype retire  on case when the retire status is closed and amount gretaer than $ 250 it will  automatically create expire recordtype  record on case object. if amount is less than 250 it will create  live recordtpe record on case object. My code is

 

public static void createRecords (List<Case> newObjects)   

 

      {

 

        set<id> expired = new set<id>();

 

         List<Case>update=new List<Case>();

 

        List<Case>CToCreate=new List<Case>();

 

        

 

         for(Case cs:newObjects)

 

         {

 

           if(cs.RecordTypeId==retiredRecordType && cs.status=='Closed')

 

           {

 

          

 

           expired.add(cs.id);

 

           

 

           }

 

         

 

         }

 

         

 

       update =[select id, AR_Balance__c, Accountid,status from Case where id in:expired];

 

       for(Case c:update)

 

        {

 

            if(c.amount>=250)

 

            {

 

           

 

              Case ct = new Case();

 

              ct.RecordTypeId = expiredRecordType;

 

              ct.status='New';

 

              ct.id=c.accountid;

 

             ct.subject='testing';

 

              CaseToCreate.add(ct);

 

            }

 

            

 

            else if(c.amount<200 )

 

            {

 

             

 

              Case ct = new Case();

 

              ct.RecordTypeId = liveRecordType;

 

              ct.status='New';

 

               ct.accountid=c.accountid;

 

              ct.subject='testing';

 

              ToCreate.add(ct); 

 

            }

 

        }

 

        

 

          if(ToCreate.size()>0)

 

          {

 

             insert ToCreate;

 

          }

 

      

 

    }
1 Antwort
  1. 21. Apr. 2018, 17:56
    Hi Rahul,

     

    I think you can do the same thing using a process builder. Give it a try and let us know if it doesn't work.
0/9000