In this post I am going to share an interesting custom “Lightning Component” with you. I called it “Opportunity Close Countdown” this is basically a count down timer which will tell us the remaining time left to close an opportunity. This timer works based on the “closed date” field on the opportunity record.
I think this component will be very helpful for sales user, they can keep eyes on their opportunity close date very easily so that they can close the deal within the time limit.
var interval = window.setInterval(
//Fomart the Opportunity Close Date
var opptyCloseDate = new Date( closeDate+" 00:00:00 ");
var now_date = new Date();
// time difference between opportunity close date and today's date
var timeDiff = opptyCloseDate.getTime()- now_date.getTime(); //Return the number of milliseconds since 1970/01/01
//seprate the timeDiff into total seconds, minnutes, hours and days.
var seconds=Math.floor(timeDiff/1000); // seconds
var minutes=Math.floor(seconds/60); //minute
var hours=Math.floor(minutes/60); //hours
var days=Math.floor(hours/24); //days
//get the remaining hours, minutes, seconds.
//put the calculated value in lightning component Attributes.
👉 Steps to add this component on the Opportunity detail page:
- Go To Opportunity record detail page.
- Click on setting icon shown in the screenshot below | click on ‘Edit Page’.
Lightning app builder page will open. Here drag the component in the section. (Shown in the screenshot below).
You can find this “Lightning Component” complete code 👉 here.