+ Start a Discussion
Sarita PatelSarita Patel 

Trigger to copy formula field changed value to another custom field.

Object: Lead
Formula feild: Lead_Age__c
Custom feild: Lead_Age2__c

I wrote some triggers but somehow they are not working... thank you in advance 
Boss CoffeeBoss Coffee
A formula field will not fire a trigger because the value isn't stored. The formula will be executed and calculated each time it is accessed.

What is your use case for this trigger?
Sarita PatelSarita Patel
Actually, I need to send email notification based on two criteria. 1. Lead Age is > 1 day and 2. Unread Owner (I have created this field with picklist value yes or no and these value change based on process builder). However, workflow rule is working only for if record created or edited and I need it to send a notification when lead age IS CHANGED  0 day to 1. and IS CHANGED is not working with lead age as it is formula field. 
Boss CoffeeBoss Coffee
Could you possibly use a time-dependent action to update the field and send an email notification one day after the Created Date of the Lead?
Bishal Singh 12Bishal Singh 12

Hello Sarita,

You can do it with workflow in condition you can give ISCHANGED(Lead_Age2__c) in formula evaluate to true.
 

Or in your trigger you can use before update or after update

and check if trigger.oldmap and trigger.newmap holds the same value or different.

If its different you can copy the value to different fields.

Sarita PatelSarita Patel
Hello Bishal, 

yes, that's why I need to copy formula field value to Lead_Age2__c  as formula field is not supported with ISCHANGED function.