Fire Toast Message from Visualforce Page

Fire Toast Message from Visualforce Page

Witn Spring19, you can fire toast messages from Visualforce pages now.

Toast messages can be sent using “showToast” method which is the latest member in sforce.one object. Which means, these messages can only be displayed in Salesforce Mobile app and would not be supported in desktop experience. The change applies to Lightning Experience, Lightning communities, and all versions of the mobile app.

 

Check out below example to display toast messages:

<apex:page >

    <script type=”text/javascript”>     

    window.onload = setupPage;

    function setupPage() {

        //function contains all code to execute after page is rendered

        //Showing a toast message

        sforce.one.showToast({

            “title”: “Hello There!!”,

            “message”: “I am a toast message being fired from visualforce page”,

            “type”: “success” //supported types are error, success, info, warning

        });

    }

    </script>

    

    <div> Toast Message Demo </div>

</apex:page>

 

The supported types are, error, success, info and, warning. Once you add above VF page in Salesforce Mobile Navigation (Setup > Salesforce Navigation), you would see the visualforce tab in the menu. Opening the VF page in mobile app will display a toast like below:

Source: Salesforce Release Notes

Also Read: Share Data Between Lightning Component & Visualforce Page

Also Read: Apex/Visualforce New Features & Changes – #Winter19 Development Track Highlights

Manish Choudhari

I am a certified Salesforce Application & System Architect and Developer working on Salesforce Technology since 2014. Currently, I have 14 Salesforce certifications along with OCPJP (Oracle Certified Profession JavaSE6 Programmer) working in Salesforce.com Hyderabad as a Technical Engineer. Writing technical blogs, learning new technologies and frameworks and sharing knowledge is my hobby.

Leave a Reply

Close Menu