• Brandon Detwyler
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi,
  I need to autopopulate the number datatype field after the record is deleted.
For example,
I have 5 records and their serial numbers are  1,2,3,4 and 5. If i delete the 3rd record , then the serial number of the 4th record should be automatically populated as 3 and 5th records as 4.
How to achieve this delete operation?

My Trigger Code:

trigger RecordSteps on Record__c(before insert,after delete) 
    {
        List<Record__c> cp = new List<Record__c>(); 
        set<id> id = new set<id>();
        List <AggregateResult> requirements = new List<AggregateResult>();  
       if (Trigger.isBefore && Trigger.isInsert)
       { 
        for(Record__c pt:trigger.new)
        {
         requirements=[select Count(Seq__c) from Record__c];
         if(requirements.size() > 0)
         {
         for(AggregateResult ar:requirements)
         {
         pt.Seq__c = Decimal.ValueOf(String.ValueOf(ar.get('expr0')));
          }
      }
      }
}
      if (Trigger.isAfter&& Trigger.isDelete) 
      {
      for(Record__c pt1:trigger.old)
        {
          }
          }   
     }