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
NerijusNerijus 

How to add confirmation message?

Hi all,

I have a visualforce page which is being innitiated from the button on the record page.
<apex:page standardController="Contact" extensions="MyApexClass" action="{!create}">
<apex:form >
<apex:inputHidden value="{!contact.id}"/>
</apex:form>
</apex:page>
I have an apex class which looks like this:
public class MyApexClass
{
    String contactId;
    
    public MyApexClass(ApexPages.StandardController controller)
    {
        this.contactId = controller.getId();
    }
    public PageReference create()
    {
        DO STUFF.....

        Pagereference pg = new Pagereference('/' + contact.Id);
        pg.setRedirect(true);
        return pg;
    }
When I'm being returned to contact page I want to show the message to the user like this one:
User-added image
 
SwethaSwetha (Salesforce Developers) 
HI Nerijus,
You can use the addMessage() method provided by the ApexPages class in your create() to display a toast message after the page is redirected back to the Contact page

Try below
public PageReference create()
{
    // DO STUFF....

    ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Record saved successfully!'));

    PageReference pg = new PageReference('/' + contact.Id);
    pg.setRedirect(true);
    return pg;
}
Related: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/apex_pages_message.htm

https://www.eternussolutions.com/2019/04/03/now-toast-your-messages-from-visualforce-pages-too/

If this information helps, please mark the answer as best. Thank you