-
I want that only my contact section will refresh when i click on delete button
I want that only my contact section will refresh when i click on delete button
<apex:page controller="AccountWithConPicklist" sidebar="false"> <apex:form > <apex:pageBlock title="Account Name"> Account Names <apex:selectList value="{!AccId}" size="1"> <apex:selectOptions value="{!AccountNames}"/> <apex:actionSupport event="onchange" reRender="a" action="{!showContact}"/> </apex:selectList> <apex:pageBlock title="Contacts" id="a"> <apex:messages /> <apex:pageBlockTable value="{!listWrapper}" var="wrap"> <apex:column > <apex:inputCheckbox value="{!wrap.checked}"/> </apex:column> <apex:column headerValue="Name"> <apex:outputText value="{!wrap.con.Name}" rendered="{!!wrap.checked}"/> <apex:inputText value="{!wrap.con.Name}" rendered="{!wrap.checked}"/> </apex:column> <apex:column headerValue="Phone"> <apex:outputText value="{!wrap.con.Phone}" rendered="{!!wrap.checked}"/> <apex:inputText value="{!wrap.con.Phone}" rendered="{!wrap.checked}"/> </apex:column> <apex:column headerValue="Email"> <apex:outputText value="{!wrap.con.Email}" rendered="{!!wrap.checked}"/> <apex:inputText value="{!wrap.con.Email}" rendered="{!wrap.checked}"/> </apex:column> </apex:pageBlockTable> <apex:pageBlockButtons > <apex:commandButton value="Delete" action="{!del}"/> <apex:commandButton value="Edit" action="{!edit}"/> <apex:commandButton value="Save" action="{!save}"/> <apex:commandButton value="Cancel" action="{!cancel}"/> </apex:pageBlockButtons> </apex:pageBlock> </apex:pageBlock> </apex:form> </apex:page>
public class AccountWithConPicklist { public String AccId{get;set;} public list<contact> Conlist{get;set;} public List<SelectOption> getAccountNames() { List<SelectOption> accOptions= new List<SelectOption>(); accOptions.add( new SelectOption('','--Select--')); for( Account acc : [select Id,name from Account ] ) { accOptions.add( new SelectOption(acc.Id,acc.name)); } return accOptions; } public List<WrapperClass> listWrapper {get;set;} public void showContact() { listWrapper = new List<WrapperClass>(); List<Contact> conlist = [SELECT Name,Phone,Email FROM contact where accountid=:AccId AND Name like 'a%']; if(conlist.size()>0) { for(contact con:conlist) { listWrapper.add(new WrapperClass(con)); } } } public class WrapperClass { public Boolean checked {get;set;} public contact con {get;set;} public WrapperClass(contact con) { this.con=con; checked=false; } } public PageReference del() { List<Contact> listconForDel=new List<Contact>(); List<WrapperClass> listconWrapper = new List<WrapperClass>(); for(WrapperClass w : listWrapper) { if(w.checked==true) { listconForDel.add(w.con); } else { listconWrapper.add(w); } } system.debug('listconWrapper----'+listconWrapper.size()); system.debug('listconForDel----'+listconForDel.size()); if(listconForDel.size()>0) { delete listconForDel; listWrapper=listconWrapper; return NULL; } else { system.debug('---------------'); ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Select atleast one employee to delete')); return NULL; } } public PageReference edit() { return null; } public PageReference save() { return null; } public PageReference cancel() { return null; } }
Log In to reply.
Popular Salesforce Blogs
![](https://images.forcetalks.com/wp-content/uploads/2024/05/22201021/sa_1716408603salesforcecrmimplementationservices%201.jpg)
Seamless Data Migration: Best Practices in Salesforce Implementation Services
Salesforce CRM is a robust tool with countless applications. Businesses invest in CRM implementation with the goal of managing complex business challenges while achieving no…
![Record Level Security](https://images.forcetalks.com/wp-content/uploads/2021/04/22173618/Record-Level-Security.jpg)
Learn About Record Level Security in Salesforce
In Salesforce, when we have to grant access to a specific record within the object, then it is done with the help of Record level…
![](https://images.forcetalks.com/wp-content/uploads/2021/11/03092628/sa_1635931480week2Salesforce%20Revenue%20Cloud01%201.jpg)
How Salesforce Revenue Cloud Can Drive Revenue Growth Across Sales and Finance Through Revenue Operations (Revops)
In today’s business landscape, companies across the globe are redefining their sales and finance revenue operations (RevOps) to meet fluctuating customer requirements and fluid market…
Popular Salesforce Videos
Create Surveys in Salesforce | Salesforce Tutorial
Learn how to create surveys in Salesforce. In this video, the following points will be covered - 1. Build A Survey Learn how to build…
How To Set Up Gmail With Salesforce | Salesforce Development Tutorial
Learn how to set up Gmail with Salesforce. The following points will be covered in this tutorial - 1. Lightning for Gmail Get a brief…
5 Things Salesforce Lightning Does Better
In this 30-minute recorded webinar, Jamie Grettum talked about her favorite Lightning features, how to set them up, and how to get hands-on experience with…