Display 🚩 Flags conditionally using formula in Salesforce Lightning

In this article I will share an example to display Flag images based on a formula value. 

In my case the requirement was to display flags on lead based on user's login time. Let say if user is checking the lead in between 08:00 AM EST to 05:00 PM EST so the formula should show Green flag and user can call the client.

But if user is logged in after his working hours then it should show 🚩 Red flag to indicate user that he/she can not call the client at the moment.

To accomplish the functionality I created a formula field with return type TEXT on Lead object and applied below formula to do the trick.


IF((HOUR(TIMENOW())-4)>7 && (HOUR(TIMENOW())-4)<17, 
   IMAGE("/img/samples/flag_green.gif", "Green Flag"),
   IMAGE("/img/samples/flag_red.gif", "Red Flag")

In the above formula I am using TIMENOW() to get the current time and HOUR() to get the hour only from the TIMENOW() function. The result will be in GMT so to convert it to EST I have subtract 4 hours from it. So in above formula if the user will login  between 8AM to 5PM EST so it will display Green flag else it will show Red one.


If you have any question please leave a comment below.
If you would like to add something to this post please leave a comment below.
Share this blog with your friends if you find it helpful somehow !

Keep Coding 

Post a Comment