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
LakshmanLakshman 

Send Email every 3 months to specific user depending on a particular scenario

Hi All,

 

I have a requirement where I need to Send Email to fixed users on following conditions:

 

1. I have a field on Account named PublishDate__c which is of type Date.

2. I need to Send email to Users(which are fixed) after every three months from this Date, so it would be like: we will send email after 3 months from this date and then after 6 months then 9 and so on.

 

How can we achieve this, through Scheduler would it be possible? If yes how and if no then is there any other way out?

 

Please help me on this.

 

Regards,

Lakshman

Best Answer chosen by Admin (Salesforce Developers) 
LakshmanLakshman

Well I have figure it out, the query would be like follows:

public Date d = system.today().addMonths(-3);

String query = 'Select Id, PublishDate__c From Account where PublishDate__c =:d';

 

Thanks!

 

Regards,

Lakshman

All Answers

IspitaIspita

Hi Lakshman,

Yes a scheduled batch job would be the best bet for you. In you code you can have to

  • check email sending date where-in you can fetch all the accounts for whom (PublishDate__c + 90) = today
  • Now for all these records you can send mail to the fixed list of users as defined by you , this information can be hardcoded or can be stored in some object or custom setting as per your convinience.

Hope this helps.

LakshmanLakshman

How would be the query?

Would it be like:

Database.query('Select Id, PublishDate__c From Account where (PublishDate__c + 90) =:today()');

the above query gives me an erroe like unexpected token 90.

 

I appreciate if you can tell me the query.

Thanks

 

Regards,

Lakshman

LakshmanLakshman

Well I have figure it out, the query would be like follows:

public Date d = system.today().addMonths(-3);

String query = 'Select Id, PublishDate__c From Account where PublishDate__c =:d';

 

Thanks!

 

Regards,

Lakshman

This was selected as the best answer