1

Requirement is to send an email alert to Lead owner with the list of Leads that satisfied the condition. But the email alert has to be sent only once for a given lead record. I have implemented a schedulable and batch class to implement this requirement. Understood that I can create a boolean or date field on the Lead object and update the flag or date field on the lead record when the email alert is sent. Then in the SOQL filter the Leads where boolean or Date is empty so that lead record which has a value(meaning email sent) can be excluded.

I am wondering is there any other method that this requirement can be achieved. I am trying to think by not updating a field when the email alert is sent so that we can avoid subsequent executions(reevaluation of workflows, validation rule, triggers etc) on the lead record.

1
  • I think we don't have any other better workarounds for this issue.
    – Pavan tej
    Commented Nov 8, 2016 at 6:14

1 Answer 1

1

You can schedule the batch job at a specific time on each day and consider those leads which has been created within 24 hours.

This way you can eliminate the creation of other boolean fields in Lead object.

Also, from your code you cannot guarantee that the email has been reached to the recipient before updating the boolean indicator field.

So, this approach will work for your scenario.

7
  • Thanks for the response. The batch is scheduled to run once a day. So let's say the batch job ran today and sent Lead Record 1, Lead Record 2 to Owner 1. By tomorrow when the same batch executed Lead Record 1 & 2 should not be sent to Owner 1 and Owner 1 should get emails only if there are new leads other than 1 & 2.
    – user28452
    Commented Nov 8, 2016 at 6:23
  • yes, check the lead creation date within 24 hours, so the next day those leads will not be picked up Commented Nov 8, 2016 at 6:26
  • Within 24 hours will not cover historical leads post deployment of the batch apex right?
    – user28452
    Commented Nov 8, 2016 at 6:28
  • That is your one time migration effort Commented Nov 8, 2016 at 6:31
  • you can create a separate script for that which will run a single time Commented Nov 8, 2016 at 6:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .