function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Nagaraju MogiliNagaraju Mogili 

I want to Edit and delete the records of an Account Object in visualforce page

User-added image

I have displayed the Account object records and Edit and Delete buttons on the Visualforce Page, can anyone please let me know how can i Edit and delete from the vf page.
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Nagaraju, Hope it will be helpful.

Please mark it as best answer if the information is informative.so that question is removed from an unanswered question and appear as a proper solution.

Thanks
Rahul Kumar

 
Nagaraju MogiliNagaraju Mogili
Hi Rahul,

Thanks for your Reply, unfortunately it was not working.

can you check this code once, if it ok in your Org, please let me know.

Regards,
Nagaraju Mogili
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Nagaraju,

Check the below code:
vf page 
-------------------
<apex:page controller="DataTableEditRemoveController">
<apex:form id="form" >
<apex:pageBlock title="Accounts">
<apex:pageMessages ></apex:pageMessages>
<apex:pageBlockTable value="{!accs}" var="row">

<apex:column value="{!row.Name}"/>
<apex:column value="{!row.BillingStreet}"/>
<apex:column >
      <apex:outputLink title="" value="/{!row.id}/e?retURL=/apex/{!$CurrentPage.Name}" style="font-weight:bold">Edit</apex:outputLink>        
</apex:column>
<apex:column >
      
    <apex:commandButton action="{! DeleteAccount}" value="Delete" title="Delete" reRender="form">
      <apex:param name="delId" assignTo="{!delId}" value="{!row.Id}" /> 
    </apex:commandButton>
    
</apex:column>
    
</apex:pageBlockTable>
</apex:pageBlock>

</apex:form>
</apex:page>
 
controller :
public class DataTableEditRemoveController {

public List<Account> accs { get; set; }
public String delId { get; set; }


public DataTableEditRemoveController() {
//load account data into our DataTable
LoadData();
}

private void LoadData() {
accs = [Select id, name, BillingStreet, BillingCity, BillingPostalCode, BillingCountry from Account limit 20];
}

public void DeleteAccount(){
    system.debug('delId' + delId);
 Account acc = [select id,Name from account where Id =:delId];
if (acc != null) {
Delete acc;
    LoadData();
}
}


}
Thanks
Rahul Kumar
 
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Nagaraju,

May I know have you got the chance to check the above code.if so information is informative mark it as best answer.so that question is removed from an unanswered question and appear as a proper solution.

Thanks
Rahul Kumar