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
dev rana 10dev rana 10 

Problem in delete the record through controller

Hello Every on i m trying to delete record through controller but not able to do.

This is my vf page
<apex:page sidebar="false" showHeader="false" controller="customerEditRemoveController">
      <apex:form id="form" >
             <apex:pageBlock title="Customer Detail">
                <apex:pageMessages ></apex:pageMessages>
                   <apex:pageBlockTable value="{!Custreg}" var="row">
                        <apex:column >
                           <apex:outputLink title="" value="/{!}/e?retURL=/apex/{!$CurrentPage.Name}" style="font-weight:bold">Edit</apex:outputLink>&nbsp;|&nbsp;
                           <a href="javascript:if (window.confirm('Are you sure?')) DeleteAccount('{!row.Id}');" style="font-weight:bold">Del</a>
                        <apex:column value="{!row.Name__c}"/>
                        <apex:column value="{!row.Last_Name__c}"/>
                        <apex:column value="{!row.Mobile__c}"/>
                        <apex:column value="{!row.Email__c}"/>
                        <apex:column value="{!row.Country__c}"/>
     <apex:actionFunction action="{!deletecustomer}" name="deletecustomer" reRender="form" >
       <apex:param name="RegCustId" value="" assignTo="{!SelectedRegCustId}"/>

This is my Controller
public class customerEditRemoveController {
    public List<devrana__RegCustomer__c> Custreg { get; set; }
    //used to get a hold of the account record selected for deletion
   public string SelectedRegCustId { get; set; }
     public customerEditRemoveController() {
       //load account data into our DataTable
    private void LoadData() {
       Custreg = [Select id, devrana__Address__c,devrana__Adults__c,devrana__Arival_Time__c,devrana__child__c,devrana__Country__c,devrana__Departure_time__c,devrana__Email__c,devrana__Last_Name__c,devrana__Mobile__c,devrana__Name__c,devrana__Reservation_Type__c,devrana__Rooms__c from devrana__RegCustomer__c limit 20];
      public void deletecustomer(){
            if (SelectedRegCustId == null) {
           devrana__RegCustomer__c tobeDeleted = null;
         for(devrana__RegCustomer__c rec : Custreg)
            if (rec.Id == SelectedRegCustId) {
            tobeDeleted = rec;
       //if account record found delete it
      if (tobeDeleted != null) {
       Delete tobeDeleted;
         //refresh the data


Veenesh VikramVeenesh Vikram
Try changing
<a href="javascript:if (window.confirm('Are you sure?')) DeleteAccount('{!row.Id}');" style="font-weight:bold">Del</a>

<a href="javascript:if (window.confirm('Are you sure?')) deletecustomer('{!row.Id}');" style="font-weight:bold">Del</a>

as the name of Action Function is "deletecustomer".

Hope this helps you!

Best Regards
hi dev,

you need to match function in javascript and target name.
you can either:
<a href="javascript:if (window.confirm('Are you sure?')) deleteAccount('{!row.Id}');" style="font-weight:bold">Del</a>
<apex:actionFunction action="{!deletecustomer}" name="deleteAccount" reRender="form" >
<a href="javascript:if (window.confirm('Are you sure?')) deletecustomer('{!row.Id}');" style="font-weight:bold">Del</a>
<apex:actionFunction action="{!deletecustomer}" name="deletecustomer" reRender="form" >

dev rana 10dev rana 10
Thanks Veenesh Vikram & 
FearNone as per your Sugation my problem is solve.
Veenesh VikramVeenesh Vikram
Hi Dev,

Kindly mark the solution as solved and close the thread.