5

I need to send a reminder email to task owner x days before due date. Please tell me the ways to crack this requirement. Some thoughts

  1. Time triggered workflows, But I doubt they can't be part of managed package
  2. Apex batch job that run every day and scan through all task and send emails

Note: This solution has to go in managed package.

1
  • As for #1 - is that a typo? : 'can' be part of... ?
    – Saariko
    Sep 11 '12 at 8:16
3

Im not sure it will work for you as your using a managed package but I've used a mix of both to solve a similar problem.

We needed to send out a reminder email every 2 weeks. To achieve this we added both a hidden date field and hidden check box.

When the record is created the date field is set to Today() and the checkbox is set to FALSE.

In the background we have a scheduled Apex job that runs every morning at 8am. The scheduled job checks if any of the dates are < Today - 14 Days and if they are it sets the checkbox to TRUE.

Setting the checkbox to TRUE and and the date field being < Today - 14 Days triggers a workflow that sends the email, then field updates the record so that the date is Today() and the checkbox is FALSE.

In your instance I would think you should be able to replace the workflow i'm using with an Apex Trigger that does exactly the same thing (We used the workflow so that the Client can alter the email content)

global class dailyCron implements Schedulable {
    public static String CRON_EXP = '0 0 8 * * ? *'; // 8am Every Day

    global static String scheduleIt() {
        dailyCron cron = new dailyCron();
        return System.schedule('Daily Cron', CRON_EXP, cron);
    }


    global void execute(SchedulableContext sc) {

        //Send CRB Emails
        Contact [] cons = [SELECT Id FROM Contact WHERE Last_Email__c <= LAST_N_DAYS:14];

        for(Contact con : cons){
            con.Send_Email_Reminder__c = true;  
        }

        update cons;

    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.