Yes, we can achieve this. We have to do these steps:
- Create a LWC/Aura component that can show toast message.
- The Aura component will use localStorage to track whether it's first time if yes then we will show the toast and update in localStorage.
- And if it's not first time then we simply skip the toast message.
- This component will not have any UI elements.
- Now drop the component on the home page using edit page.
- Logout and login again and you should see toast when you visit the page first time.
Here is the sample code of AURA:
var alertisFirstView = sessionStoragelocalStorage.getItem('alert''isFirstView') || '';
if (alertisFirstView !=== 'Yes') {
toastEvent.fire(); / /Fire* toastShow eventmessage to use as this is first view. */
sessionStorage localStorage.setItem('alert''isFirstView', 'Yes');
}
With sessionStorage, you can display message once when you log in to application first time. If you refresh the page then message do not appear. But if you close the browser and login again, it again display the message.
With localStorage, you can display message once after that you close the broswer and login again, it does not display.
In my requirement I wanted to use local storage.