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
Alessandro Patricelli 9Alessandro Patricelli 9 

showToast on VisualForce Page isnt working? Help ;c

Hi All,
I am trying to make a VisualForce page that on Load it show a simple JS Toast..
But i am keeping getting the following error:

Uncaught ReferenceError: sforce is not defined
    at showToast

This is my Visual Force Page, what i am doing wrong?:

<apex:page standardController="Account" lightningStylesheets="true" >
    <script type="text/javascript">
        window.onload = showToast();
        function showToast() {
            sforce.one.showToast({
                "title": "Attenzione",
                "message": "Test Message.",
                "type": "warning"
            });
        }
        
    </script>
</apex:page>

Thanks for help :) really apprecciated.
Javier PereroJavier Perero
thank you
ravi soniravi soni
hy Friend,
Your  code is looking good but I think you have to follow some steps for showing toast on detail page or home page.
//Here is my code.
<apex:page standardController="Account"  lightningStylesheets="true">
    <script type='text/javascript'>
        window.onload = showToast();
        function showToast() {
            sforce.one.showToast({
                "title": "Attenzione",
                "message": "Test Message.",
                "type": "warning"
            });
            
        }
        
    </script>
</apex:page>

#1. Setup=>search Visualforce page  and select your page edit it and check Available for Lightning Experience, Experience Builder sites, and the mobile app.
#2. go to home page or detail page => drag visualforce and select your page Name from right side of VisualforcePage Name Column.
#3. Now Save it and Check.

The toast would be there.
don't forget to mark it as best answer.
Thank you