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
santhosh konathala 17santhosh konathala 17 

Hi can anybody help on this.Below is my vf page controller not deleting records.Please help where I did wrong?

vf page:

<apex:page controller="AccountDelete" >
<apex:form >
<apex:outputlabel value="RecordToDelete "/>
  
<apex:inputText value="{!RecordToDelete}" label="RecordToDelete"/> <br/><br/>
<apex:outputlabel value="phone"/>
<apex:inputText label="phone"/><br/><br/>
<apex:commandButton value="Delete" action="{!DeleteName}"/>
<apex:param name="AccountDelete" value="abc" assignTo="{!RecordToDelete}"/>


</apex:form>

</apex:page>

Controller:

Public with sharing class AccountDelete{

Public Id RecordToDelete{get;set;}

Public List<account> acclist {get;set;}

public void DeleteName()
{
 acclist=Database.query('Select id from account where id=:'+ RecordToDelete);
system.debug('Record id to delete ='+ RecordToDelete);
if(acclist.size()>0 & acclist !=null)
{
delete acclist;
}
}
}

 
Ankur Saini 9Ankur Saini 9
Hi santhosh

try this:
<apex:page controller="AccountDelete" >
    <apex:form >
        <apex:outputlabel value="Record To Delete   "/> 
            <apex:inputText value="{!RecordToDelete}"/> <br/><br/>
        <apex:outputlabel value="Phone   "/>
            <apex:inputText /><br/><br/>
        <apex:commandButton value="Delete" action="{!DeleteName}"/>
    </apex:form>
</apex:page>


Public with sharing class AccountDelete{

Public string RecordToDelete{get;set;}
Public List<account> acclist {get;set;}

public pagereference DeleteName(){
    acclist=[Select id from account where id=:RecordToDelete];
        if(acclist.size()>0 & acclist !=null){
            delete acclist;
           }
   return null;
  }
}

Thanks
Ankur Saini
sfdcMonkey.comsfdcMonkey.com
hi
try below code
Public with sharing class AccountDelete{

Public Id RecordToDelete{get;set;}

Public List<account> acclist {get;set;}

public void DeleteName(){
 acclist = Database.query('Select id from account where id=\''+ RecordToDelete + '\'');
  system.debug('Record id to delete ='+ RecordToDelete);
  
 if(acclist != null && acclist.size() > 0  ){
      delete acclist;
      }
    }
}
thanks
let me inform if it helps you and mark it best answer if it helps you

 
santhosh konathala 17santhosh konathala 17
Hi Soni,

Thanks for your reply..

The code which you sent not deleting any record when I pass record name through vf page.

Regards,
santhosh