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.
Pranshu Goyal, Director of Products at Mirekta, states: “We envision DSM to be used by every small to a medium-sized organization dealing with bad data and want to get rid of duplicates easily with no cost. We have faced issues dealing with duplicates in our organization. That inspired us to make a solution that is not only simple to use but can be used widely to make the organization’s data clean to make them more efficient and productive. We want DSM to be a solution for every organization looking for duplicate management capability better than the Salesforce out-of-the-box solution with no additional cost.”
Recent Posts
- Salesforce Higher Education: Transforming Modern Universities15 Apr 2025 Blog
- AI Agents The Future of Business Applications09 Apr 2025 Blog
- Why Purpose-Built AI Agents Are the Future of AI at Work07 Apr 2025 Blog
- How the Atlas Reasoning Engine Powers Agentforce03 Apr 2025 Blog
- Leveraging AI for Code Analysis, Real-Time Interaction, and AI-driven Documentation02 Apr 2025 Use-case
- Transforming Healthcare with AI-Powered Patient Health Monitoring with Fitbit & Salesforce01 Apr 2025 Use-case
- 5 Myths About Autonomous Agents in Salesforce28 Mar 2025 Blog
- AI for Nonprofits: Boosting Fundraising with Salesforce Einstein, Agentforce, and Smarter InsightsShape25 Mar 2025 Use-case
- AI-Powered Vaccination Scheduling with Einstein Copilot & Predictive AI21 Mar 2025 Use-case
- Leveraging AI to Enhance Sales Effectiveness13 Mar 2025 Use-case
- Revolutionizing Manufacturing with AI: Predictive Maintenance, Supply Chain Optimization, and More11 Mar 2025 E-Book
- NetSuite for Manufacturing: Streamlining Operations and Solving Key Challenges07 Mar 2025 Blog
- How to Build Your First Agent in Salesforce Agentforce24 Feb 2025 Blog
- ERP vs Salesforce Revenue Cloud: Which One is Right for Your Business?24 Feb 2025 E-Book
- Revolutionizing Manufacturing with Salesforce: A Playbook for Efficiency & Growth18 Feb 2025 E-Book
- Salesforce 2025 Game-Changing Trends You Need to Know28 Jan 2025 Blog
- Agentforce 2.0: Everything You Need to Know About the Latest Update22 Jan 2025 Blog
- The Ultimate Guide to NetSuite Development: Tools and Techniques10 Jan 2025 Blog
- How Salesforce Nonprofit Cloud Transforms Fundraising Strategies10 Jan 2025 Blog
- The Impact of Salesforce Development Partners on Small and Medium Businesses08 Jan 2025 Blog
Categories
Featured by



