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
Bikram Keshari JenaBikram Keshari Jena 

We have an requirement to pull Formula Text field in Apex Trigger.

Hi All,

We have an requirement to pull Formula Text field in Apex Trigger. We are trying to fetch the field in Apex Trigger on Lead but it showing old value on the trigger. We need the latest value when the trigger will be fired upon the lead save/submit.

We need some solution or workaround to meet this.

Appiciated if anybody has solution on this.

Regards,
Bikram
 
Khan AnasKhan Anas (Salesforce Developers) 
Hi Bikram,

Greetings to you!

Formula fields are calculated when queried from the database. Formula fields pull data directly out of the database and generate the value of the field from that when they are queried. Formula records don't really update their records, they're calculated at runtime when you're viewing it.

Make sure you are using after trigger because, in before triggers, the trigger context has the new values for the trigger object loaded, but nothing has been committed yet, so any calls to the database will return the old values for formula fields and regular fields. In after triggers, this is not the case.

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Thanks and Regards,
Khan Anas
Bhargavi TunuguntlaBhargavi Tunuguntla
Hi Bikram,

Use 'After Trigger' to fetch the newly Calculated value. 

Thanks.
Hope this will be useful.