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
Nicolas BockNicolas Bock 

How to tr

Hey, 

Here's my use-case : 

I want Salesforce to automatically fire an email when a field is changed in the User Object. 
So I'm using an Apex Trigger to do that. 

The only problem is that I want the email to be sent 24 hours after the field has changed and I'm struggling to find a way to do so...

Is there a way to delay an action called by an apex trigger ? 

Thanks ! 
 ​

GauravGargGauravGarg

Hi Nicolas,

You need to create a Schedule Job that would run every day or twice a day. The schedule job will query all the User's record get updated in last 24 hours and send an email accordingly. 

Thanks,

Gaurav
Skype: gaurav62990

Akshay_DhimanAkshay_Dhiman

Hi Nicolas,
You Can do this by using schedule apex job so that on every 24 hours the mail gets sent when a particular user field gets updated.
There is no need to write trigger for this situation.

You can take help by this below links for building schedule job,

https://help.salesforce.com/articleView?id=code_schedule_batch_apex.htm&type=5

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_scheduler.htm

Thanks,

Akshay