function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
krios demokrios demo 

how to display popup when user login to salesforce?

I have written the lwc code for the modal popup to display the pending opportunities of the currently logged-in user.

Currently, my popup is displayed on the home page once the home page appears on screen. i.e. onloading.

But I want to display the popup on home page once user login to salesforce and came to the home page. if a user opens any other tab and came back to the home page it must not be displayed on home page. it should be displayed on home page when the user login to salesforce.

Note: I don't want to create login flows.


HTML file:

<template>
    <template if:true={isModalOpen}>
        <div class="slds-modal slds-fade-in-open slds-backdrop">
        <section role="dialog" tabindex="-1" aria-labelledby="modal-heading-01" aria-modal="true" aria-describedby="modal-content-id-1" class="slds-modal slds-fade-in-open">
            <div class="slds-modal__container">
                <header class="slds-modal__header">
                    <lightning-button-icon icon-name="utility:close" alternative-text="Close this window" size="large" variant="bare-inverse" onclick={closeModal} class="slds-modal__close">
                    </lightning-button-icon>
                    <h2 id="modal-heading" class="slds-text-heading_medium slds-hyphenate">Pending Opportunity Alerts</h2>
                </header>
               
                <div class="slds-modal__content" id="modal-content-id">
                    <p><b> &nbsp; Hello!...
                    </b></p>
                    <p><b> &nbsp; You have some pendings opportunities...Please work on it before month end.
                    </b></p>
                    <p><b> &nbsp; For more detials see the reports.
                    </b></p>
                </div>
               
                <footer class="slds-modal__footer">
                    <button class="slds-button slds-button_neutral" onclick={navigateToReport} title="View Report">View Report</button>
                    <button class="slds-button slds-button_brand" onclick={submitDetails} title="Close">Close</button>
                </footer>
            </div>
        </section>
    </div>
    </template>
 </template>
==============================================
JS File:

import { LightningElement, track ,wire} from 'lwc';
import { NavigationMixin } from 'lightning/navigation';
import Id from '@salesforce/user/Id';
import getCount from '@salesforce/apex/PendingOppCount.getCount';
export default class POPUP extends NavigationMixin (LightningElement) {
    @track isModalOpen = false;
    @track userId = Id;
    constructor(){
        super();
        this.getCount();
        console.log('Currently Logged in Useer ID:-',this.userId);
    }
    openModal() {
       
        this.isModalOpen = true;
    }
    closeModal() {
       
        this.isModalOpen = false;
    }
    submitDetails() {
       
        this.isModalOpen = false;
    }
    getCount(){
        console.log('Inside getCount');
        getCount({CurrUserId: this.userId})
        .then(result => {
            //console.log('Inside getCount');
            this.data = result;
            console.log('Inside getCount',this.data);
            this.error = undefined;
            if(this.data > 0){
                console.log('Inside openModal');
                this.openModal();
            }else{
                console.log('Inside closeModal');
                this.closeModal();
            }
           
        })
        .catch(error => {
            console.log('Inside error',this.error);
            this.error = error;
            this.data = undefined;
        });
}
    navigateToReport() {
        const config = {
            type: 'standard__webPage',
            attributes: {
                url: '/lightning/r/Report/00O5g00000GmtuKEAR/view?queryScope=userFolders'
            }
        };
        this[NavigationMixin.Navigate](config);
    }
}
==============================================

xml file:

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>55.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__AppPage</target>
        <target>lightning__RecordPage</target>
        <target>lightning__HomePage</target>
        <target>lightning__FlowScreen</target>
    </targets>
</LightningComponentBundle>
Richard Reed 3Richard Reed 3

I believe the answer you are looking for is here:

 

https://developer.salesforce.com/forums/?id=9062I000000IEo4QAG

PriyaPriya (Salesforce Developers) 

Hi Krios,

Greetings to you!

You can use Login Flows. Please refer to the below links which might help you further with the above requirement.

http://docs.releasenotes.salesforce.com/en-us/winter15/release-notes/rn_forcecom_security_login_flows.htm

https://developer.salesforce.com/docs/atlas.en-us.securityImplGuide.meta/securityImplGuide/security_login_flow_examples.htm

https://automationchampion.com/2014/12/11/display-notice-when-users-log-in-to-salesforce-3/

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,

Priya Ranjan

Alex TobaAlex Toba
I have also same (https://bbqbuck.com/) questions in my mind..