A basic example to edit/delete records individually.
Here i have taken two pages editdelete and editfun
on clicking edit in page 1 i am redirected to page 2 to edit the record and save it, after saving i am redirected to sobject detail page.
Below is code for page 1 :-
<apex:page showHeader="false" sidebar="false" controller="editcon" tabStyle="Acc__c">
<apex:form >
<apex:sectionHeader title="edit/delete"/>
<apex:pageBlock >
<apex:pageBlockTable value="{!stun}" var="stu">
<apex:column >
<apex:param name="sid" value="{!stu.id}"/>
</apex:column>
<apex:column value="{!stu.name}"/>
<apex:column value="{!stu.Name__c}"/>
<apex:column value="{!stu.Age__c}"/>
<apex:column value="{!stu.Gender__c}"/>
<apex:column headerValue="Action">
<apex:commandLink value="EDIT" action="{!edit}">
<apex:param name="cid" value="{!stu.id}" assignTo="{!ecid}"/>
</apex:commandLink>
<apex:commandLink value="DELETE" action="{!deletecon}">
<apex:param name="cid" value="{!stu.id}" assignTo="{!dcid}"/>
</apex:commandLink>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
page 1 screen shot:-
controller class:-
public class editcon {
list<Acc__c> stun = new list<Acc__c>();
list<Acc__c> stun1 = new list<Acc__c>();
public string ecid{get;set;}
public string dcid{get;set;}
public PageReference deletecon() {
stun1 =[Select Name, name__c, age__c from Acc__c where id=:dcid];
delete stun1;
pagereference pg= new pagereference('/apex/editdelete');
pg.setRedirect(True);
return pg;
}
public PageReference edit() {
pageReference pg = new pagereference('/apex/editfun?id='+ecid);
pg.setRedirect(false);
return pg;
}
public list<Acc__c> getStun() {
stun = [select name, name__c, age__c,gender__c from Acc__c];
return stun;
}
}
}
page 2:-
<apex:page showHeader="false" sidebar="false" standardController="Acc__c"tabstyle="Acc__c">
<apex:form >
<apex:sectionHeader title="Edit the record"/>
<apex:pageBlock tabStyle="Acc__c">
<apex:pageBlockButtons location="both">
<apex:commandButton value="save" action="{!save}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection >
<apex:inputField value="{!Acc__c.Name__c}"/>
<apex:inputField value="{!Acc__c.Age__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
screen shot of page 2:-