Apex Code for Creating Recurring Event in Salesforce Lightning
Author
January 17, 2018
In this article, I am sharing my approach and code required for fetching days for recurring events in Salesforce Lightning. The use cases could be creating a recurring pickup, order placement, etc. You would need basic knowledge of Apex and Salesforce Lightning.
This screen will give you an idea about the recurring UI.
Scenario: –
User can select a Start Date, End Date, Recurring weeks , and Day. Now according to selected fields, the record will get recur in the future.
Step1: – We need to create an aura enabled apex method to fetch dates between the Start, Date, and End Date.
Apex Method.
@AuraEnabled
public static Integer getDays(string startDate ,string endDate){
integer noOfDays= date.valueOf(startDate).daysBetween(date.valueOf(endDate));
return noOfDays;
}
Step2: – Now in the lightning component controller we need to store that dates accordingly.
Lightning controller.
getDates: function(component, event, helper){
var startDate = component.find(“dateField”).get(“v.value”);
var endDate = component.find(“dateFieldend”).get(“v.value”);
var recurWeek = component.find(“week”).get(“v.value”);
var recurWeek1 = (Number(recurWeek)+1)*7;
var startDate1 = new Date(startDate);
var endDate1 = new Date(startDate);
alert(‘recurWeek1===’+recurWeek1);
var selectedDays = [“”,””,””,””,””,””,””];
var checkboxes=component.find(“check”);
for(var c in checkboxes){
if(checkboxes[c].get(“v.checked”)){
var dayvalue = checkboxes[c].get(“v.value”)
selectedDays.splice(dayvalue,1,dayvalue);
}
}
alert(“startDate == “+startDate1+” endDate == “+endDate1+” recurWeek == “+recurWeek1+” selectedDays == “+selectedDays);
var startDay = startDate1.getDay();
var dateArray = [];
var finaldates = [];
var action=component.get(“c.getDays”);
action.setParams({“startDate”:startDate,”endDate”:endDate});
action.setCallback(component,function(response){
if(response.getState()==”SUCCESS”){
var noOfDays =response.getReturnValue();
for(var i=startDay;i<noOfDays;i++){
if(startDay == selectedDays[i]){
dateArray.push(startDate1);
}
else if(i%7==selectedDays[i%7] && selectedDays[i%7]!= “”){
var date = new Date(startDate1.setDate(startDate1.getDate()));
dateArray.push(date);
}
startDate1.setDate(startDate1.getDate() + 1);
}
}
});
$A.enqueueAction(action);
}
It is that simple, isn’t that? Feel free to send me your questions by adding comments to this blog.
Recent Posts
-
XML Parsing: Using MINIDOM Vs Element Tree (etree) in Python02 Jul 2025 Blog
-
A step by step Guide to create Salesforce web-to-lead form30 Jun 2025 Blog
-
How AI is Transforming User Experience Design in 202526 Jun 2025 Blog
-
How a Salesforce NPSP Consultant Can Elevate Nonprofit Impact25 Jun 2025 Blog
-
Salesforce Load and Performance Testing: Essentials, Importance & Execution23 Jun 2025 Blog
-
Salesforce Website Integration Boost Leads, Automation & Customer Experience11 Jun 2025 Blog
-
Driving Results in Manufacturing with Salesforce Manufacturing Cloud11 Jun 2025 Blog
-
Accelerating Growth with NetSuite SuiteCommerce02 Jun 2025 Blog
-
Salesforce Service Cloud Services streamlining operations29 May 2025 Blog
-
AI for Nonprofits: Mirketa & Exec Precision Webinar27 May 2025 Press Release
-
AI for Nonprofits: Use Cases, Tools & Implementation Strategies20 May 2025 Webinar
-
Javascript Frameworks for Salesforce Lightning Design System18 May 2025 Blog
-
Building a Smart Campus with Salesforce Student Information System: A Road to Smarter Education16 May 2025 Blog
Categories
Featured by



