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
dreamrealdreamreal 

Scheduling apex

This is sort of an unusual thing so bear with me as I try to explain it. I have an apex trigger that sends an email to a person when an opportunity is set to a certain stage. What I want to do however, is be able to send that email at a certain time, say at the end of the day, 4 pm. So if that trigger is activated at some point during that day for that opportunity, is there a way to send that email at a specific time?

bob_buzzardbob_buzzard

I think you could do this using a scheduled batch job.  You could set a field on the opportunity to indicate that an email needs to be sent, then set up your batch apex to query all opportunities with that field set to the appropriate value, then generate the emails and finally send them.  

 

I don't think there's any way to generate the email and then hold it until a certain time.

SFDCRRSFDCRR

Yes you can do this. 

 

You do not have to use trigger - to send email . you can use the workflow - for the first case

 

you can use time based workflow to send email to at the end of the when ny condition is met.