Use of ActionStatus in Visualforce page salesforce

By | November 20, 2019

apex:actionStatus

A component that displays the status of an AJAX update request. An AJAX request can either be in progress or complete.

Using actionstatus, we can also display some gif (graphic Interchange Format), which shows to user that their request is in progress.

Here we have also shown Apex:message after data inserted succesfully.

Apex Controller

public class actionStatus {
    public Account account{get;set;}
    public actionStatus(){
        account = new Account();
    }
    public void save(){
        try {          
            //insert account;             
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Record insert successfully'));
            
        } catch(DmlException e) {           
            
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please enter Valid Data'));            
            
        }
    }
    
}

Vf Page

<apex:page controller="actionStatus" tabStyle="Account">
    <apex:form id="formId">
        <apex:pageBlock id="pgBlckId" title="New Account">
            <apex:pageMessages />
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save" reRender="pgBlckId" status="actStatusId"/>
                <apex:actionStatus id="actStatusId" >
                    <apex:facet name="start" >
                        <img src="/img/loading.gif" />                    
                    </apex:facet>
                </apex:actionStatus>
            </apex:pageBlockButtons>
            
            <apex:pageBlockSection id="pgBlckSecId" title="Account Information" collapsible="false">
                <apex:inputField value="{!account.name}"/>
                <apex:inputField value="{!account.Phone}"/>
                <apex:inputField value="{!account.Type}"/>
                <apex:inputField value="{!account.Rating}"/>
                <apex:inputField value="{!account.Industry}"/>
                <apex:inputField value="{!account.site}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Output

When we enter the data and click on save loading image status has been shown to the user

Leave a Reply

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