Here you can find a code example of the event calendar for Lightning Web Components on Salesforce Platform.
The sample is implemented with the help of JavaScript Scheduler library - DHTMLX Scheduler.
- Enable the Developer Hub in your organization
- Install the Salesforce CLI
-
Change login url (sfdcLoginUrl) in sfdx-project.json to url of your SalesForce organization
-
Create scratch org
sfdx org login web -d
sfdx org create scratch -f config/project-scratch-def.json -d
- Publish code
sfdx project deploy start
- Open scratch org in browser
sfdx org open
The scratch org already has Scheduler app which you can check, or go to "Setup : Lighting Apps", create a new Lighting App and drop the Scheduler from the list of available components.
getEvents in force-app/main/default/classes/SchedulerData.cls returns list of events, adjust this query as necessary.
force-app/main/default/lwc/scheduler/scheduler.js contains code of web component
function unwrap(fromSF){
const data = fromSF.events.map(a => ({
unwrap functions controls how data from SalesForce is converted to dhtmlxScheduler compatible objects. You will need to modify this code if you will want to provide some additional data properties from SalesForce to the dhtmlxScheduler
initializeUI(){
const root = this.template.querySelector('.thescheduler');
root.style.height = this.height + "px";
const scheduler = window.Scheduler.getSchedulerInstance();
initializeUI creates an instance of scheduler. This is the perfect place to configure the scheduler by using its API
scheduler.createDataProcessor(function (entity, action, data, id) {
switch (action) {
case "create":
createDataProcessor defines data saving rules, they need to be adjusted if you will want to save some extra fields along with the default Event's data.
force-app/main/default/staticresources/scheduler contains a trial version of the Scheduler ( it will show a warning message time to time ). For production usage you will need to replace js and css files in this archive with ones from enterprise/ultimate Scheduler package.
The earliest version of dhtmlxScheduler that is fully compatible with SalesForce LWC is dhtmlxScheduler v6.0.1.
- Documentation: https://docs.dhtmlx.com/scheduler/
- dhtmlxScheduler product page: https://dhtmlx.com/docs/products/dhtmlxScheduler/
- Video tutorial: https://youtu.be/IceDT8O1Pys
- About DHTMLX Scheduler in Salesforce: https://dhtmlx.com/docs/products/demoApps/salesforce-scheduler/
Star our GitHub repo ⭐
Read us on Medium 📰
Follow us on Twitter 🐦
Like our page on Facebook 👍