+ Start a Discussion
uuuu 

Increment Filed value using trigger

Hey Folks,
Plese help me to write trigger.
I have 3 custom object 
Employee__c, Leaves__c ,Month__c.
On Leaves__c has Lookup with Employee__c and 1 date field Leave_Date__c.
And On Month__c Master-datail with Employee__c and 1 Leaves_Taken__c number field.

After inserting new Leave__c for that Employee__c It will increment the value by 1 of custom field Leaves_Taken__c  for that Month in Month__c object.

If delete the Leaves then decrement the value by 1.

Like Example in below
In Month__c obj, we now have a record for each Month for that Employee. So if leave was approved & taken on 10th Jan 2020, then increment the "Leaves Taken" count on Jan 2020 record in Month__c by 1. On insert, increment to happen. On Delete, decrement to happen. On update, both decrement for old value of Leave Date in Month__c  obj & increment of new value in respective records.

Please me out to write trigger for it.
Thanks in advance 

Regards,
Anita Sodhi
ANUTEJANUTEJ (Salesforce Developers) 
Hi Anita,

I found the below link which has an implementation of incrementing and decrementing on an object, can you please have a look at it once and in case if it helps can you please mark this as best answer so that it can be used by others in the future.

>> https://developer.salesforce.com/forums/?id=906F00000008z0ZIAQ

Regards,
Anutej