You need to sign in to do that
Don't have an account?
SalesforceAddict
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;
}
}
<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;
}
}
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
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.
You can use below code for delete record with loader.
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
Please mark as the solution if it solved your purpose.
Thanks,
Sohan Raj Gupta