+ Start a Discussion
Sainath VenkatSainath Venkat 

loading message until success or failure message on VF Page

How to show loading icon on VF Page until success or failure message appears.

I have a button on child object which will update the child and parent record, button is using VF Page and apex class.
I want to show loading image until success or failure message appears, can anyone help me out on this.

Apex class:
public class DeviationButton {
    public Lease_2__c a{get;set;}
    public String str;
    set<Id> opportunityId = new set<Id>();
    List<Lease_2__c> leaseupdate = new List<Lease_2__c>();
    List<Lease_2__c> leaselist = new List<Lease_2__c>();
    List<Opportunity> opptoUpdate = new List<Opportunity>();
    public DeviationButton(ApexPages.StandardController controller) {
        string currentRecordId  = ApexPages.CurrentPage().getparameters().get('id');
        Lease_2__c allleases = [select Id, Opportunity__c,Deviation_Required__c,DeviationCount__c, Stage__c from Lease_2__c Where Id=: currentRecordId];
          //  allleases.Stage__c = 'Legal Review';
        if(  allleases.Stage__c == 'Deviation')
              str = 'Deviation';
              allleases.Stage__c = 'Legal Review';
            if(allleases.DeviationCount__c == 0 || allleases.DeviationCount__c == null){
                allleases.Deviation_Required__c = false;
            else if(allleases.DeviationCount__c >= 1){
                allleases.Deviation_Required__c = true;
        Opportunity allopps = [select Id, StageName from Opportunity where Id =: allleases.Opportunity__c];
        allopps.StageName='Deal Approved';
    public void MyActionMethod()
        for(Lease_2__c l : leaseupdate)
            if(str == 'Deviation' && l.stage__c =='Legal Review' )
                  ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'You cannot Recall Deviation if Stage is not in Deviation'));
           update leaseList;
           update opptoUpdate;
           ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Lease Record Has Been Successfully Recalled. Thank You!'));
        //update leaseupdate;

VF Page:
<apex:page standardController="Lease_2__c" extensions="DeviationButton" action="{!MyActionMethod}" lightningStylesheets="true" showQuickActionVfHeader="false"  > 
    <apex:pageMessages ></apex:pageMessages><h3 style="color:green">
             <!-- <b>Lease Has Been Successfully Recalled. Thank You!</b>-->

ANUTEJANUTEJ (Salesforce Developers) 
Hi Sainath,

>> https://salesforce.stackexchange.com/questions/65580/popup-spinner-style-apexactionstatus

The above link has a similar implementation can you try checking it once?

Let me know if it helps you and close your query by marking it as the best answer so that it can help others in the future.