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

(Visited 511 Times)

Leave a Reply

Your email address will not be published. Required fields are marked *