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
Rebekah LillyRebekah Lilly 

Display spinner or message on VisualForce page

I have a custom button on a related list to allow the users to select records and then update a field with a single click. I only want the button on the related list, not on list views, and I toyed with various methods of processing the list, but a VisualForce page seems to be the easiest and most efficient and gives me the expected results. The user clicks the button, the VF page displays briefly, the selected records (if any) are updated, and the page redirects back to the record. Everything works as expected. The problem is that when the VisualForce page is shown... it is blank and I would like to show some wording that it is processing or ideally a spinner. I am using an action attribute and I don't want the user to have to click on anything else... I would just like them to know something is happening instead of seeing a blank white page.

Suggestions greatly appreciated.

VF Page:
<apex:page standardController="PPR_Line__c" recordSetVar="listLines" extensions="PPRLine_UpdateController" action="{!updatePPRLines}" > </apex:page>

Apex:
public class PPRLine_UpdateController {
    
    public List<String> pprLinesSet    { get; set; }
    public List<PPR_Line__c> selectedPPRLineRecords    { get; set; }
    public Id pprId { get; set; }
    public String currentRecId { get; set; }
    
    public PPRLine_UpdateController(ApexPages.StandardSetController setController) {
        currentRecId = ApexPages.currentPage().getParameters().get('id');
        selectedPPRLineRecords = (PPR_Line__c[])setController.getSelected();
        pprLinesSet = new List<String>();
        for(sObject sobj : setController.getSelected()) {
            pprLinesSet.add( (String)sObj.get('Id') );
        }
    }
    
    public PageReference updatePPRLines() {
        
        List<PPR_Line__c> pprLines = [SELECT Id, Parts_Received__c 
                                      FROM PPR_Line__c 
                                      WHERE Id IN :pprLinesSet];
        List<PPR_Line__c> pprLinesToUpdate = new List<PPR_Line__c>();
        if (!pprLines.isEmpty()) {
            for(PPR_Line__c line : pprLines) {
                     PPR_Line__c updline = new PPR_Line__c();
                    updline.id = line.id;
                    updline.Parts_Received__c = true;
                    pprLinesToUpdate.add(updline);
            }
            update pprLinesToUpdate;
        
            List<PPR__c> pprUpdate = new List<PPR__c>();
            PPR__c upd = new PPR__c();
            upd.id = currentRecId;
            upd.Refresh__c = true;
            pprUpdate.add(upd);
            update pprUpdate;
        }
        
        // return to page
        PageReference pageRef = new PageReference('/' + currentRecId);
        pageRef.setRedirect(true);
        return pageRef;
        
    }

}
VinayVinay (Salesforce Developers) 
Hi Rebekah,

Check below example to add spinner on vf page.

https://simplysalesforce.com/2014/09/16/add-a-spinner-on-a-visualforce-page/
https://salesforce.stackexchange.com/questions/191203/visualforce-with-slds-spinner-embedded-in-a-page-layout#:~:text=If%20you%20want%20to%20use,live%20in%20an%20apex%3AactionStatus

Please mark as Best Answer if above information was helpful.

Thanks,