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
venkat bojjavenkat bojja 

Lightning Component force:showToast event nor working in Developer Console

Hi Team,
I Have one issue...
When i am tring to use var showToast = $A.get("e.force:showToast");  like this in my controller.Js  it is not working through the developer console.
But it is working into tab level. I required to work this into developer console. Is there any work aroud it. Please help me on this...
Thanks in advance...

Thanks
Venkat
SandhyaSandhya (Salesforce Developers) 
Hi,

When you try to launch the component via app , standard events (toast, navigateToSobject, etc) will be undefined.

Refer below link for similar discussion.

https://salesforce.stackexchange.com/questions/156089/error-implementing-forceshowtoast-cannot-read-property-setparams-of-undefin
 
Please mark it as Solved if my reply was helpful. It will make it available for other as the proper solution.
 
Thanks and Regards
Sandhya
 
venkat bojjavenkat bojja
Hi Sandhya,
Thanks for your reply but i know this information. I required any work around it. If there any possibility over come this issue. So please help me on this.

Thanks
Venkat
Ajay K DubediAjay K Dubedi
Hi venkat,

When you try to launch the component via app (demoApp in your case) , standard events (toast,  navigateToSobject,  etc)  will be undefined.
        var toastEvent = $A.get("e.force:showToast");
        toastEvent will have "undefined " always.

Therefore launch your toastComponent in LEX via app builder or lightning quickaction or drag to detail page to check how it works.

Otherwise you will try this code for Show Toast:
COMPONENT:
<aura:attribute name="notificationmessage" type="String"/>
<aura:handler action="{!c.doinit}" value="{!this}" name="init"/>
<div class="slds-modal slds-fade-in-open errorDiv slds-hide" aura:id="warningDiv">
        <ui:inputText aura:id="articleURL"/>
        <div class="demo-only" style="height: 8rem;">
            <div class="slds-notify_container slds-is-relative">
                <div class="slds-notify slds-notify_toast slds-theme_success" role="alert">
                    <div class=" slds-m-left_xx-large">
                        <div class="slds-notify__content slds-m-left_small slds-align_absolute-center slds-m-left_xx-large">
                            <lightning:icon alternativeText="Success" iconName="utility:success" size="small"
                                            class="buttonColor slds-m-right_small" />
                            <h2 class="slds-text-heading_small ">{!v.notificationmessage}</h2>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
CONTROLLER:
({
    doinit : function(c, e, h) {
        

        c.set("v.notificationmessage", 'This is example of display toast.');
                              $A.util.removeClass(c.find('warningDiv'), 'slds-hide');
                               window.setTimeout($A.getCallback(function() {
                               $A.util.addClass(c.find('warningDiv'), 'slds-hide');
                                  }), 3000);
                 
    },
})
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks,
Ajay Dubedi