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
LorrMcLorrMc 

My first trigger please help!

Hi, 

I need to write a tigger that will send a different email template based on a date field. 
I have an object called references that is a lookup to the contact, I need to send an email at 60,30 and 10 before the experation date and I cant use process builder or workflow so im REALLY stuck.
Could someone please give me a sample code for a trigger that I can tweek. 

Thank You,

Lorr
Raju yadavRaju yadav
Hi LorrMc,
Please find below link that might help you.
https://success.salesforce.com/answers?id=9063A000000l409QAA
LorrMcLorrMc
Hi Raju, 

Thank you for ths however I cant use a workflow or process builder, I have tried in process builder but it wont reavluate and I would have to create over 50 workflows which is not possible. 

Lorr
Deepali KulshresthaDeepali Kulshrestha
Hi LorrMc,

Please follow the below steps and links with the help of these steps and link you can solve your problem, it may be helpful to you.

1. From Setup, click Create | Workflow & Approvals | Workflow Rules.
2. Click New Rule.
3. In the Object drop-down list, choose Object name (Order Product), and click Next.
4. In the Rule Name text box, enter relevant text.
5. In the Evaluate the rule when a record is: field, select:
   created and anytime it's edited meet sunsequently criteria
6. In the Rule Criteria section:
   objectname: expiration date       notequals            Null
7. Click Save & Next.
8. Add the corresponding Time Trigger Action
   180days        before         Expiration date
9. Click Save.
10. Activate the Workflow Rule.

Link: https://help.salesforce.com/articleView?id=workflow_time_dependent.htm&type=0
Link: https://success.salesforce.com/answers?id=9063A000000l409QAA


I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha