Deleting records:

In this scenario we used custom controller to perform delete action, and pageblocktable to display records and command link to delete individual records. In this we used ‘apex:param’ for transmitting individual record ids from vf to apex class.

Visualforce page:
<apex:page controller=”DeleteTestingNew” sidebar=”false”>
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:pageBlockTable value=”{!records}” var=”r”>
<apex:column headerValue=”Action”>
<apex:commandlink value=”Delete” action=”{!doDelete}”>
<apex:param name=”rId” value=”{!r.Id}” assignTo=”{!rId}”/>
</apex:commandlink>
</apex:column>
<apex:column headerValue=”Name”>
{!r.name}
</apex:column>
<apex:column headerValue=”city”>
{!r.City__c}
</apex:column>
<apex:column headerValue=”phone”>
{!r.Phone__c}
</apex:column>
<apex:column headerValue=”country”>
{!r.Country__c}
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

ApexClass:
public with sharing class DeleteTestingNew {
public String rId{get;set;}
DataLoadTest__c delDlt = new DataLoadTest__c();
public PageReference doDelete() {
delDlt=[select Id from DataLoadTest__c where id =:rId];
delete delDlt;
pagereference ref=new pagereference(‘/apex/newdelete’);
ref.setredirect(true);
return ref;
}
List<DataLoadTest__c> lstdlt = new List<DataLoadTest__c>();
public List<DataLoadTest__c> getRecords() {
lstdlt =[select id,name,city__c,country__c,phone__c from DataloadTest__c];
return lstdlt;
}
}