You need to sign in to do that
Don't have an account?
Akshay Alandkar
what to do ?
In account detail page create a button”Delete contacts” which displays and delete the
corresponding contacts of the particular account record.
corresponding contacts of the particular account record.
You have two option.
1. For Lightning you can Create a Quick action and accociate with Lightning Component.
2. For Classic you can create javascript button and wrrite a script to delete contacts
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
All Answers
You have two option.
1. For Lightning you can Create a Quick action and accociate with Lightning Component.
2. For Classic you can create javascript button and wrrite a script to delete contacts
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
Vf Page :
<apex:page id="SortPage" standardController="Account" extensions="DelteContactController" showHeader="false">
<apex:form id="myForm">
<apex:sectionHeader title="Contact"/><br/>
<apex:pageBlock >
<apex:pageBlockButtons location="bottom" >
<apex:CommandButton value="Delete" action="{!deletecontact}" reRender="table" />
</apex:pageBlockButtons>
<apex:pageBlockSection title="Contact Records" collapsible="false" columns="1"/>
<br/>
<body>
<table id="contacttable" class="display">
<thead>
<tr>
<th style="width:10%;">Select</th>
<th style="width:25%;">Name</th>
<th style="width:30%;">Account Name</th>
<th style="width:25%;">Email Id</th>
</tr>
</thead>
<tbody>
<apex:repeat value="{!AccObj}" var="contactinfowrp" id="tableInd">
<apex:repeat value="{!contactinfowrp}" var="con">
<tr >
<td><apex:inputCheckbox value="{!con.checked}"/></td>
<td>{!con.sObj.Name}</td>
<td>{!con.sObj.Account.Name}</td>
<td>{!con.sObj.Email}</td>
</tr>
</apex:repeat>
</apex:repeat>
</tbody>
</table>
</body>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller :
public class DelteContactController {
public account acc {get; set;}
public List<ContactInfoWrapper> ContactsWrapper {get; set;}
public DelteContactController(ApexPages.StandardController controller)
{}
public List<ContactInfoWrapper> getAccObj(){
Id id = apexpages.currentpage().getparameters().get('id');
acc = [SELECT id from account where Id =:id];
list<contact> conList=[SELECT Id,Account.Name,Name, Email FROM Contact where AccountId=:acc.id];
ContactsWrapper = new List<ContactInfoWrapper>();
for(Contact con:conList){
ContactsWrapper.add(new ContactInfoWrapper(con,true));
}
return ContactsWrapper;
}
//Wrapper class
public class ContactInfoWrapper
{
public Contact sObj{get;set;}
public Boolean checked {get;set;}
public ContactInfoWrapper(Contact con,boolean selectedBox)
{
sObj = con;
checked=selectedBox;
}
}
//Delete
public pageReference deletecontact()
{
list<Contact> conlist = new list<Contact>();
for(ContactInfoWrapper c : ContactsWrapper)
{
if(c.checked == true)
{
conlist.add(c.sObj);
}
}
if(conlist.size()>0)
{
Delete conlist ;
}
pageReference pr = new pageReference('/lightning/o/Account/list?'+acc.id);
return pr ;
}
}