Opportunity Close Countdown | ⚡ Lightning Component

Hello There,

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(
$A.getCallback(function() {
//Fomart the Opportunity Close Date
var opptyCloseDate = new Date( closeDate+" 00:00:00 ");
//Todays date
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.
hours %=24;
minutes %=60;
seconds %=60;
//put the calculated value in lightning component Attributes.
}), 1000);

The setInterval() javascript method calls a function or it evaluates an expression at specified intervals (in milliseconds).

👉 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.

👉 https://sfdclesson.com/opportunity-close-countdown-%E2%9A%A1-lightning-component/


Arun Kumar

Arun Kumar

Arun Kumar is a Certified Salesforce developer and Salesforce Champions (Platform Champions), a Computer Science graduate, working on the Salesforce platform and providing customer solutions using force.com as a Salesforce consultant/developer. He is the founder of SFDCLessons. :)

Leave a Reply