You need to sign in to do that
Don't have an account?
Akshay Alandkar
need test class for this one ...
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,false));
}
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 ;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Contact Deleted Successfully !!!'));
}
pageReference pr = new pageReference('/lightning/o/Account/list?'+acc.id);
return pr ;
}
}
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,false));
}
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 ;
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Contact Deleted Successfully !!!'));
}
pageReference pr = new pageReference('/lightning/o/Account/list?'+acc.id);
return pr ;
}
}
Please try the below test class:
Thanks,
Maharajan.C
All Answers
<apex:page id="SortPage" standardController="Account" extensions="DelteContactController" showHeader="false">
<apex:form id="myForm">
<apex:sectionHeader title="Contact"/><br/>
<apex:pageBlock >
<apex:pageMessages id="showmsg"></apex:pageMessages>
<apex:pageBlockButtons location="bottom" >
<apex:CommandButton value="Delete" action="{!deletecontact}" reRender="table,showmsg" />
</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>
Please try the below test class:
Thanks,
Maharajan.C