Monday, January 21, 2019

Show Toast messages in Visualforce pages

This post explains how to fire toast messages from visualforce page.
In spring 19 release salesforce introduces the sforce.one.showToast({toastParams}) function in sforce.one object.
by using the function you can show different severity like success, error, info, warning.
Note: The change applies to Lightning Experience, Lightning communities, and all versions of the mobile app.
Example:
VF page
<apex:page lightningStylesheets="true">
    <script>
        function showToast() {
            sforce.one.showToast({
                "title": "Success!",
                "message": "Welcome to salesforce code crack.",
                "type": "success"
            });
        }
    </script>
    <apex:form >
        <apex:page >
            <apex:commandButton value="Show Toast" onclick="showToast();" />
        </apex:page>
    </apex:form>
</apex:page>
Enable the Available for Lightning Experience, Lightning Communities, and the mobile app permission.
Check below screenshot
once you enable the checkbox, add the visualforce page in salesforce mobile navigation
Demo

Happy Learning!!!

No comments:

Post a Comment