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
SalesforceAddictSalesforceAddict 

how to apply loader on delete button

VF page----------------------------
<apex:page controller="editDeleteContactRecords" >
    <apex:form >
        <apex:pageBlock title="Account Detail">
    
        <apex:pageBlockSection >
        <apex:outputField value="{!acc.Name}"/>
        <apex:outputField value="{!acc.Phone}"/>
        <apex:outputField value="{!acc.Fax}"/>
        <apex:outputField value="{!acc.AccountNumber}"/>
        </apex:pageBlockSection>
        
        <apex:pageBlockSection title="Contacts" collapsible="false" columns="1">
        
        
        <apex:pageBlockTable value="{!acts}" var="con">
        
       <apex:column headerValue="Action">
        <apex:commandLink value="Edit |" action="{!editContact}">
        <apex:param value="{!con.Id}" name="selectedContactId" assignTo="{!selectedContact}"/>
        </apex:commandLink>
        <apex:commandLink value="Del" action="{!deleteSelectedContact}">
        <apex:param value="{!con.id}" assignTo="{!delSelContId}" name="delContId"/>
        </apex:commandLink>
        </apex:column>     
        <apex:column value="{!con.Name}"/>
        <apex:column value="{!con.Email}"/>
        <apex:column value="{!con.Title}"/>
        
        </apex:pageBlockTable>
        
       </apex:pageBlockSection>
        
        </apex:pageBlock>
    </apex:form>

</apex:page>


Apex class----------------------------
public class editDeleteContactRecords
{
public Account acc {get;set;}
public Id id;





     public editDeleteContactRecords (){
     
           id  = ApexPages.CurrentPage().getparameters().get('id');
           acc  =  (id==null)?new Account():[select  Name,Phone,fax,AccountNumber From Account where Id =:id];
     
     
     }
     
      public List<Contact> getacts(){
          
          Id id  = ApexPages.CurrentPage().getparameters().get('id');
          List<Contact> acts = [select id,Name,Title,Email,Phone from Contact where AccountId =: id ];
         
          
         return acts;
        
        
          
          // parameterValue = ApexPages.CurrentPage().getparameters().get('nameParam');
           
       }
     
    
    public PageReference editContact(){
    
     String selectedContact =apexpages.currentPage().getParameters().get('selectedContactId');
    PageReference pg=new PageReference('/'+'apex/UpdateDetail?id='+selectedContact);
    return pg;
        
    }
    // Initialize setCon and return a list of records
     public PageReference deleteSelectedContact(){
     String delSelContId= ApexPages.CurrentPage().getparameters().get('delContId');
       
        if(delSelContId!=null){
        Contact delContact = [Select Id from Contact where Id=:delSelContId];
        delete delContact;
        }
        
        return null;
        
    }  

}
Sohan Raj GuptaSohan Raj Gupta
Hi Sachin,

Right now you are using apex:commandLink for delete record and your method is returning PageReference, so in this case your loader will not show.

You can achive your goal using ActionFunction, ActionSupport and ActionStatus.

Using ActionStatus you can show loader.

Hope this will help you. Let me know if it helped or you need any more assistance. 

Please mark this is as the solution if it solved your purpose.

Thanks,
Sohan Raj Gupta 
SalesforceAddictSalesforceAddict
ok bro thnx
SalesforceAddictSalesforceAddict
if i use action status then i have to remove pagereference or it will work with page reference
 
Sohan Raj GuptaSohan Raj Gupta
Hi Sachin,

yes, it will work with PageReference, but in this case if your page will relaod fast then it will not show to you. So use ActionFunction or ActionSupport for this. Both are AJAX function.
SalesforceAddictSalesforceAddict
ok bro thnx
mukesh guptamukesh gupta
Hi Sachin,

You can use below code for delete record with loader.
<apex:actionRegion >
               <apex:commandButton value="Delete" onclick="if(!confirm('Are you sure?')) { return };"  action="{!deleteSelected}" reRender="pgBlock2" status="deleteStatus">                                                                                                                           
                
             </apex:commandButton>

           <apex:actionStatus id="deleteStatus">
            <apex:outputLabel value="Loading..."/>
                <apex:facet name="start">
                <div style="position: fixed; top: 0; left: 0; right: 0; bottom: 0; opacity: 0.25; z-index: 1000; background-color: black;">
                    &nbsp;
                </div>
                <div style="position: fixed; left: 0; top: 0; bottom: 0; right: 0; z-index: 1001; margin: 15% 50%">
                    <div style="display: inline-block; padding: 2px; background-color: #fff; width: 125px;">
                        <img src="/img/loading.gif" style="float: left; margin: 8px;" />
                        <span style="display: inline-block; padding: 10px 0px;">Please Wait...</span>
                    </div>
                </div>
                </apex:facet>
           </apex:actionStatus>
       </apex:actionRegion>

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh
Sohan Raj GuptaSohan Raj Gupta
Hi Sachin,

Please mark as the solution if it solved your purpose.

Thanks,
Sohan Raj Gupta