function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Akshata ShahAkshata Shah 

Hello I want to update the custom field with existing value+ New Entered value

I have custom object Resource__c with custom field Total_Allocated_Paid_Leaves__c .I want to update this field with existing value + New value.
Please Help me!
 
Best Answer chosen by Akshata Shah
Maulik D ShahMaulik D Shah
Hello Akshata,

You can use the trigger for that.
trigger updateData on Resource__c (before update) { 
  if(trigger.isBefore && trigger.isUpdate) { 
     for(Resource__c r : trigger.New) { 
        if(Trigger.oldMap.get(r.Id).Total_Allocated_Paid_Leaves__c != Null) { r.Total_Allocated_Paid_Leaves__c += Trigger.oldMap.get(r.Id).Total_Allocated_Paid_Leaves__c; 
        }
      }
   }
 }


I hope this helps you.

All Answers

Maulik D ShahMaulik D Shah
Hello Akshata,

You can use the trigger for that.
trigger updateData on Resource__c (before update) { 
  if(trigger.isBefore && trigger.isUpdate) { 
     for(Resource__c r : trigger.New) { 
        if(Trigger.oldMap.get(r.Id).Total_Allocated_Paid_Leaves__c != Null) { r.Total_Allocated_Paid_Leaves__c += Trigger.oldMap.get(r.Id).Total_Allocated_Paid_Leaves__c; 
        }
      }
   }
 }


I hope this helps you.
This was selected as the best answer
Akshata ShahAkshata Shah
Thank you so much for helping me Maulik D Shah. :)