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

Apex trigger on a Date

    Help! I'm new to Saleforce and Apex. I just had something happen in our production and I have no control over it. I need to know how to create a trigger based on a date.

Our company launched a Trial Version of a product, the user fills out the form and the Lead goes into Salesforce. I created a field that adds 'x' days onto the create date and that is the expired date calculated field. The indicator = "Y" and when the expired date is reached I want to change Indicator to "N".  All fields (expired date field, and Indicator field) are in Leads.

I don't have time to search all blogs and find the answer. I have never created a trigger before. I created a workflow, but this only seems to work when the record is created or edited, I need something that knows what day it is and then changes the indicator field.

Can anyone help?
is the Indicator field a formula field?

If so you can build it into that, then "Y" or "N" will display at run time.

A trigger only fires on insert or update.
       The indicator field is not a formula field. I actually want an e-mail to get sent out to the customer when their trial expire date reaches a certain point. So if now()>Expire date then send auto-email to user

Is this even possible? If a trigger can only be done at insert or update, this won't work...

Any ideas what will?

The Expire date = 16 days + Create Date. When Today()>=Expire date launch e-mail to user with a certain template...

deleting after re-reading your issue, time trigger might solve this.

Message Edited by mikef on 05-20-2008 05:01 PM
I did some looking and a Time Trigger might work.

You can have an event fire using a static time, like an email.

Look at the add time trigger in workflow rules this might work for you.
This sounds like what I need. I didn't know time triggers existed in the workflow. I will check into it.
It worked! I created the time trigger and it changed the indicator.

Now...when the Indicator goes to 'N' I want an auto-response e-mail to trigger to the e-mail on the Lead. So if Joe Smith signed up for our two-week trial, he gets a lead indicator = "Y" and I have an auto-repsonse that kicks off when the lead is created that sends him an e-mail letting him know we will contact him soon.

Then, in 2 weeks, the indicator (thanks to time trigger) is set to 'N' but I can't figure out how to send an auto-response to the user because the lead field is updated, but I think auto-response only works on creation? Am I correct?/

I was able to do an internal e-mail trigger to let the sales person know that Joe Smith just expired, but I can't figure out a way to auto-send Joe smith an email..
If I understand you correctly, I believe this is possible . Create a new Email Alert as a workflow action associated with your time trigger rule. The object for this Email Alert will be Lead and if you choose "Email Field" in the Recipient Type list you should be able to choose the Lead->Email field as the recipient of the alert.

It worked!!! I didn't know you could choose the lead field, that is exactly what I was looking for.