How to delete the repeat values in Visualforce page? I am passing the values in repeat function and every record has a delete button. I need each button to delete that particular record

<apex:repeat value="{!delrec}" var="del" >
    <div >
        <apex:outputText  value="{!del.testvalue}">
    <apex:commandButton value="delete" action="{!delete}">
        <apex:param value="{!del.id}" assignTo="{!delrecid}" name="{!del.id}" />


public string delrecid {get; set;} 
public void delete(){
    testobj__c delobj = [select id, FROM testobj__c where  id=:delrecid];
    delete delobj;
  • 1
    Hi, you're going to probably want to edit your question and provide some code of what you have so far.
    – sfdcfox
    Jun 30 '16 at 2:54
  • I had updated my code.could you please see once
    – user
    Jun 30 '16 at 3:04
  • put your visualforce and apex code. After deletion you need rerender the list on VFP. Jun 30 '16 at 3:19
  • In visualforce page what i need to add in rerender?could you please add any example code
    – user
    Jun 30 '16 at 3:23

After you delete the record, you need to refresh your list (delrec), or otherwise remove the value from the list.

public Id delRecId { get; set; }

public void delete(){
    for(Integer index = 0; index < delrec.size(); index++) {
        if(delrec[index].Id == delRecId) {
  • above code is not working sfdcfox.
    – user
    Jun 30 '16 at 4:01
  • 1
    @user - Could you tell the error message it gave you? His code assumes you're iterating a list of the records in your controller named "delrec" which should be a List<SObject> (generally with SObject replaced with the specific SObject you're working with here).
    – drakored
    Jun 30 '16 at 4:10
  • I had used rerender in commandbutton,working now.but first time one record is deleted then after i clicked another delete button its not working.help me on this.i had taken output panel id in rerender.but one time record is deleting second record is not deleting.
    – user
    Jun 30 '16 at 6:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.