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
Michael MMichael M 

Schedule VF template to send once a month, only for specific users

Hello, we have a VF email template. We need to send this out automatically once a month, with a few conditions:
1) It must ONLY send to users that own at least 1 Lead record
2) It must only send ONE email to each of those users
3) it must send once a month (as mentioned)

If it is helpful, here are the details of my VF email. (I am using a component and controller)

VF TEMPLATE
<messaging:emailTemplate subject="Your Team's Leads- Owner Assignments" recipientType="User" relatedToType="User">

 <messaging:htmlEmailBody >
   Hi {!RelatedTo.firstName},
  <p>The following leads have not yet been updated:</p>
   <c:leadsinfo ToID="{!RelatedTo.Id}" />
 <p>To update these leads, click on the "Lead Status" field located  in the upper right on the lead page layout.</p>
 </messaging:htmlEmailBody>

</messaging:emailTemplate>

COMPONENT
<apex:component controller="LeadsInfoController" access="global">
    <apex:attribute name="ToID" type="ID" description="the lead owner ID" assignTo="{!salesRepID}"/>
     
        <apex:datatable value="{!InactiveLeads}" var="item" border="1">
                    <apex:column headervalue=" Name ">
                        <apex:outputText value="{!item.name}"/>
                    </apex:column>

                     <apex:column headervalue=" Created Date ">
                        <apex:outputText value="{!item.CreatedDate}"/>
                    </apex:column>
       </apex:datatable>
</apex:component>

CONTROLLER
public class LeadsInfoController {
  //capture the user id
    public ID salesRepID {get; set;}
    public List<community_lead__c> ClsInfo = new List<community_lead__c>();

    public List<community_lead__c> getInactiveLeads() {
        ClsInfo = [select Name, CreatedDate  from community_lead__c where  ownerId =: salesRepID];
        return ClsInfo;
    }
}
Best Answer chosen by Michael M
ANUTEJANUTEJ (Salesforce Developers) 
Hi Michael,

Have you tried checking with flow and process builder as this scenario seems to be one that can be done with them.

Looking forward to hearing back from you.

Regards,
Anutej.

All Answers

ANUTEJANUTEJ (Salesforce Developers) 
Hi Michael,

Have you tried checking with flow and process builder as this scenario seems to be one that can be done with them.

Looking forward to hearing back from you.

Regards,
Anutej.
This was selected as the best answer
Michael MMichael M
Thank you, Anutej
ANUTEJANUTEJ (Salesforce Developers) 
Glad to help Michael. :)