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
Frank CarterFrank Carter 

visualforce page edit/delete error

Hello,
I have a problem with a Visualforce page. I have a controller which aids in displaying a visualforce page with the Edit & Delete functionality. However, my delete doesn't seem to work. When I try to delete, the error is:

The name can only contain underscores and alphanumeric characters. It must begin with a letter and be unique, and must not include spaces, end with an underscore, or contain two consecutive underscores. 

I made a few changes. Now the vf code is:
<apex:page controller="BDPaginationController" >
    <apex:form >
        <apex:actionFunction name="refreshPageSize" action="{!refreshPageSize}" status="fetchStatus" reRender="pbId"/>
        <apex:pageBlock id="pbId" title="Billing Details of this Month">
            <apex:pageBlockSection collapsible="false" columns="1">
                <apex:pageBlockTable value="{!BD}" var="b">
                    <apex:column >
                   <apex:outputLink title="" value="/{!b.Id}/e?retURL=/apex/{!$CurrentPage.Name}" style="font-weight:bold">Edit</apex:outputLink>&nbsp;|&nbsp;
					<a href="javascript&colon;if (window.confirm('Are you sure?')) DeleteBD'{!b.Id}');" style="font-weight:bold">Del</a>
					</apex:column>
					<apex:column value="{!b.Name}"/>
					<apex:column value="{!b.Billing_Type__c}"/>
					<apex:column value="{!b.Billing_Period__c}"/>    
					<apex:column value="{!b.Monthly_Forecast__c}"/>
					<apex:column value="{!b.End_of_Billing__c}"/>
					<apex:column value="{!b.Amount__c}"/>
					<apex:column value="{!b.Billing_Status__c}"/>
                </apex:pageBlockTable>
                 
                <apex:panelGrid columns="8"> 
                 
                <apex:selectList value="{!size}" multiselect="false" size="1" onchange="refreshPageSize();">
                    <apex:selectOptions value="{!paginationSizeOptions}"/>
                </apex:selectList>
                 
                <apex:commandButton status="fetchStatus" reRender="pbId" value="First" action="{!setCon.first}" disabled="{!!setCon.hasPrevious}" title="First Page"/> 
  
                <apex:commandButton status="fetchStatus" reRender="pbId" value="Previous" action="{!setCon.previous}" disabled="{!!setCon.hasPrevious}" title="Previous Page"/> 
  
                <apex:commandButton status="fetchStatus" reRender="pbId" value="Next" action="{!setCon.next}" disabled="{!!setCon.hasNext}" title="Next Page"/> 
  
                <apex:commandButton status="fetchStatus" reRender="pbId" value="Last" action="{!setCon.last}" disabled="{!!setCon.hasNext}" title="Last Page"/> 
  
                <apex:outputText >{!(setCon.pageNumber * size)+1-size}-{!IF((setCon.pageNumber * size)>noOfRecords, noOfRecords,
                     (setCon.pageNumber * size))} of {!noOfRecords}
                </apex:outputText> 
                       
                <apex:outputPanel >                      
                    <apex:actionStatus id="fetchStatus" >
                        <apex:facet name="start" >
                          <img src="/img/loading.gif" />                    
                        </apex:facet>
                    </apex:actionStatus>
                </apex:outputPanel> 
  
            </apex:panelGrid>  
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
 				<apex:commandButton value="Move to next month" action="!next"/>   
			</apex:pageBlockButtons>
        </apex:pageBlock>
        
        //aggiungo
         <apex:commandLink action="{!deleteBD}" onclick="if(!confirm('Are you sure?')) return false;">Del
    <apex:param value="{!b.Id}" name="idToDel" assignTo="{!BdId}"/>
</apex:commandLink>

        
        
    </apex:form>
</apex:page>

and the controller code is:
 
public class BDPaginationController{
    Public Integer size{get;set;} 
    Public Integer noOfRecords{get; set;} 
    public List<SelectOption> paginationSizeOptions{get;set;}
         
    public BDPaginationController(){
        size=10;
        paginationSizeOptions = new List<SelectOption>();
        paginationSizeOptions.add(new SelectOption('5','5'));
        paginationSizeOptions.add(new SelectOption('10','10'));
        paginationSizeOptions.add(new SelectOption('20','20'));
        paginationSizeOptions.add(new SelectOption('50','50'));
        paginationSizeOptions.add(new SelectOption('100','100'));
    }
     
    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {                
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                      [Select Id,Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c   from Billing_Detail__c Where Monthly_Forecast__c=THIS_MONTH ]));
                setCon.setPageSize(size);  
                noOfRecords = setCon.getResultSize();
            }            
            return setCon;
        }
        set;
    }
     
    //Changes the size of pagination
    public PageReference refreshPageSize() {
         setCon.setPageSize(size);
         return null;
    }
 
    // Initialize setCon and return a list of record    
     
    public List<Billing_Detail__c> getBD() {
         return (List<Billing_Detail__c>) setCon.getRecords();
    }
    

	public List<Billing_Detail__c> listBD {get;set;}
	public String SelectedBdId {get;set;}
			
	public void loadData() {
		listBD = [Select Id,Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c   from Billing_Detail__c Where Monthly_Forecast__c=THIS_MONTH ];
	}

//to delete
	public void deleteBD(){
       listBD = [Select Id,Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c   from Billing_Detail__c Where Monthly_Forecast__c=THIS_MONTH AND id =:BdId];
      if(listBD.size() > 0 || listBD[0].Id != ''){
      delete listBD;
      }
      loadData();
  
   }
  
   
}

​ I have 2 errors on developer console:
  • vf page: Unknown method 'BDPaginationController.deleteBD()' (supposed to the other )
  • BDpaginationController: Variable does not exist: BdId
Can anyone help me?

Thanks,
Frank


 
Best Answer chosen by Frank Carter
Steven NsubugaSteven Nsubuga
This should work.
Controller
public class BDPaginationController{
    Public Integer size{get;set;} 
    Public Integer noOfRecords{get; set;} 
    public List<SelectOption> paginationSizeOptions{get;set;}
         
    public BDPaginationController(){
        size=10;
        paginationSizeOptions = new List<SelectOption>();
        paginationSizeOptions.add(new SelectOption('5','5'));
        paginationSizeOptions.add(new SelectOption('10','10'));
        paginationSizeOptions.add(new SelectOption('20','20'));
        paginationSizeOptions.add(new SelectOption('50','50'));
        paginationSizeOptions.add(new SelectOption('100','100'));
    }
     
    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {                
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                      [Select Id,Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c   from Billing_Detail__c Where Monthly_Forecast__c=THIS_MONTH ]));
                setCon.setPageSize(size);  
                noOfRecords = setCon.getResultSize();
            }            
            return setCon;
        }
        set;
    }
     
    //Changes the size of pagination
    public PageReference refreshPageSize() {
         setCon.setPageSize(size);
         return null;
    }
 
    // Initialize setCon and return a list of record    
     
    public List<Billing_Detail__c> getBD() {
         return (List<Billing_Detail__c>) setCon.getRecords();
    }
    

    public List<Billing_Detail__c> listBD {get;set;}
    public String SelectedBdId {get;set;}
            
    public void loadData() {
        listBD = [Select Id,Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c   from Billing_Detail__c Where Monthly_Forecast__c=THIS_MONTH ];
    }

//to delete
    public PageReference deleteBD(){
      DELETE new Billing_Detail__c (Id = SelectedBdId);
      return null;
   }
  
   
}

Page
<apex:page controller="BDPaginationController" >
    <apex:form id="theform" >
        <apex:actionFunction name="refreshPageSize" action="{!refreshPageSize}" status="fetchStatus" reRender="pbId"/>
        <apex:pageBlock id="pbId" title="Billing Details of this Month">
            <apex:pageBlockSection collapsible="false" columns="1">
                <apex:pageBlockTable value="{!BD}" var="b">
                    <apex:column >
                   <apex:outputLink title="" value="/{!b.Id}/e?retURL=/apex/{!$CurrentPage.Name}" style="font-weight:bold">Edit</apex:outputLink>&nbsp;|&nbsp;
                    <apex:commandLink style="font-weight:bold" action="{!deleteBD}" onclick="if(!confirm('Are you sure?')) return false;" >Del <apex:param value="{!b.Id}" name="idToDel" assignTo="{!SelectedBdId}"/> </apex:commandLink>
                    </apex:column>
                    <apex:column value="{!b.Name}"/>
                    <apex:column value="{!b.Billing_Type__c}"/>
                    <apex:column value="{!b.Billing_Period__c}"/>    
                    <apex:column value="{!b.Monthly_Forecast__c}"/>
                    <apex:column value="{!b.End_of_Billing__c}"/>
                    <apex:column value="{!b.Amount__c}"/>
                    <apex:column value="{!b.Billing_Status__c}"/>
                    
                </apex:pageBlockTable>
                 
                <apex:panelGrid columns="8"> 
                 
                <apex:selectList value="{!size}" multiselect="false" size="1" onchange="refreshPageSize();">
                    <apex:selectOptions value="{!paginationSizeOptions}"/>
                </apex:selectList>
                 
                <apex:commandButton status="fetchStatus" reRender="pbId" value="First" action="{!setCon.first}" disabled="{!!setCon.hasPrevious}" title="First Page"/> 
  
                <apex:commandButton status="fetchStatus" reRender="pbId" value="Previous" action="{!setCon.previous}" disabled="{!!setCon.hasPrevious}" title="Previous Page"/> 
  
                <apex:commandButton status="fetchStatus" reRender="pbId" value="Next" action="{!setCon.next}" disabled="{!!setCon.hasNext}" title="Next Page"/> 
  
                <apex:commandButton status="fetchStatus" reRender="pbId" value="Last" action="{!setCon.last}" disabled="{!!setCon.hasNext}" title="Last Page"/> 
  
                <apex:outputText >{!(setCon.pageNumber * size)+1-size}-{!IF((setCon.pageNumber * size)>noOfRecords, noOfRecords,
                     (setCon.pageNumber * size))} of {!noOfRecords}
                </apex:outputText> 
                       
                <apex:outputPanel >                      
                    <apex:actionStatus id="fetchStatus" >
                        <apex:facet name="start" >
                          <img src="/img/loading.gif" />                    
                        </apex:facet>
                    </apex:actionStatus>
                </apex:outputPanel> 
  
            </apex:panelGrid>  
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
                <apex:commandButton value="Move to next month" action="!next"/>   
            </apex:pageBlockButtons>
        </apex:pageBlock>
        
    </apex:form>
</apex:page>

 

All Answers

Frank CarterFrank Carter
can someone help me??
Steven NsubugaSteven Nsubuga
Update your controller to this:
public class BDPaginationController{
    Public Integer size{get;set;} 
    Public Integer noOfRecords{get; set;} 
    public List<SelectOption> paginationSizeOptions{get;set;}
         
    public BDPaginationController(){
        size=10;
        paginationSizeOptions = new List<SelectOption>();
        paginationSizeOptions.add(new SelectOption('5','5'));
        paginationSizeOptions.add(new SelectOption('10','10'));
        paginationSizeOptions.add(new SelectOption('20','20'));
        paginationSizeOptions.add(new SelectOption('50','50'));
        paginationSizeOptions.add(new SelectOption('100','100'));
    }
     
    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {                
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                      [Select Id,Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c   from Billing_Detail__c Where Monthly_Forecast__c=THIS_MONTH ]));
                setCon.setPageSize(size);  
                noOfRecords = setCon.getResultSize();
            }            
            return setCon;
        }
        set;
    }
     
    //Changes the size of pagination
    public PageReference refreshPageSize() {
         setCon.setPageSize(size);
         return null;
    }
 
    // Initialize setCon and return a list of record    
     
    public List<Billing_Detail__c> getBD() {
         return (List<Billing_Detail__c>) setCon.getRecords();
    }
    

	public List<Billing_Detail__c> listBD {get;set;}
	public String SelectedBdId {get;set;}
			
	public void loadData() {
		listBD = [Select Id,Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c   from Billing_Detail__c Where Monthly_Forecast__c=THIS_MONTH ];
	}

//to delete
	public void getDeleteBD(){
       listBD = [Select Id,Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c   from Billing_Detail__c Where Monthly_Forecast__c=THIS_MONTH AND id =:SelectedBdId];
      if(listBD.size() > 0 || listBD[0].Id != ''){
      delete listBD;
      }
      loadData();
  
   }
  
   
}
However, I do not see SelectedBdId being populated anywhere in your code.
 
Frank CarterFrank Carter
Thank you for your answer.

I upgraded the code with your and I passed the value in VF (line 55):
<apex:page controller="BDPaginationController" >
    <apex:form >
        <apex:actionFunction name="refreshPageSize" action="{!refreshPageSize}" status="fetchStatus" reRender="pbId"/>
        <apex:pageBlock id="pbId" title="Billing Details of this Month">
            <apex:pageBlockSection collapsible="false" columns="1">
                <apex:pageBlockTable value="{!BD}" var="b">
                    <apex:column >
                   <apex:outputLink title="" value="/{!b.Id}/e?retURL=/apex/{!$CurrentPage.Name}" style="font-weight:bold">Edit</apex:outputLink>&nbsp;|&nbsp;
					<a href="javascript&colon;if (window.confirm('Are you sure?')) DeleteBD'{!b.Id}');" style="font-weight:bold">Del</a>
					</apex:column>
					<apex:column value="{!b.Name}"/>
					<apex:column value="{!b.Billing_Type__c}"/>
					<apex:column value="{!b.Billing_Period__c}"/>    
					<apex:column value="{!b.Monthly_Forecast__c}"/>
					<apex:column value="{!b.End_of_Billing__c}"/>
					<apex:column value="{!b.Amount__c}"/>
					<apex:column value="{!b.Billing_Status__c}"/>
                </apex:pageBlockTable>
                 
                <apex:panelGrid columns="8"> 
                 
                <apex:selectList value="{!size}" multiselect="false" size="1" onchange="refreshPageSize();">
                    <apex:selectOptions value="{!paginationSizeOptions}"/>
                </apex:selectList>
                 
                <apex:commandButton status="fetchStatus" reRender="pbId" value="First" action="{!setCon.first}" disabled="{!!setCon.hasPrevious}" title="First Page"/> 
  
                <apex:commandButton status="fetchStatus" reRender="pbId" value="Previous" action="{!setCon.previous}" disabled="{!!setCon.hasPrevious}" title="Previous Page"/> 
  
                <apex:commandButton status="fetchStatus" reRender="pbId" value="Next" action="{!setCon.next}" disabled="{!!setCon.hasNext}" title="Next Page"/> 
  
                <apex:commandButton status="fetchStatus" reRender="pbId" value="Last" action="{!setCon.last}" disabled="{!!setCon.hasNext}" title="Last Page"/> 
  
                <apex:outputText >{!(setCon.pageNumber * size)+1-size}-{!IF((setCon.pageNumber * size)>noOfRecords, noOfRecords,
                     (setCon.pageNumber * size))} of {!noOfRecords}
                </apex:outputText> 
                       
                <apex:outputPanel >                      
                    <apex:actionStatus id="fetchStatus" >
                        <apex:facet name="start" >
                          <img src="/img/loading.gif" />                    
                        </apex:facet>
                    </apex:actionStatus>
                </apex:outputPanel> 
  
            </apex:panelGrid>  
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
 				<apex:commandButton value="Move to next month" action="!next"/>   
			</apex:pageBlockButtons>
        </apex:pageBlock>
        
        //aggiungo
         <apex:commandLink action="{!deleteBD}" onclick="if(!confirm('Are you sure?')) return false;">Del
    <apex:param value="{!b.Id}" name="idToDel" assignTo="{!SelectedBdId}"/>
</apex:commandLink>

        
        
    </apex:form>
</apex:page>
controller:
public class BDPaginationController{
    Public Integer size{get;set;} 
    Public Integer noOfRecords{get; set;} 
    public List<SelectOption> paginationSizeOptions{get;set;}
         
    public BDPaginationController(){
        size=10;
        paginationSizeOptions = new List<SelectOption>();
        paginationSizeOptions.add(new SelectOption('5','5'));
        paginationSizeOptions.add(new SelectOption('10','10'));
        paginationSizeOptions.add(new SelectOption('20','20'));
        paginationSizeOptions.add(new SelectOption('50','50'));
        paginationSizeOptions.add(new SelectOption('100','100'));
    }
     
    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {                
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                      [Select Id,Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c   from Billing_Detail__c Where Monthly_Forecast__c=THIS_MONTH ]));
                setCon.setPageSize(size);  
                noOfRecords = setCon.getResultSize();
            }            
            return setCon;
        }
        set;
    }
     
    //Changes the size of pagination
    public PageReference refreshPageSize() {
         setCon.setPageSize(size);
         return null;
    }
 
    // Initialize setCon and return a list of record    
     
    public List<Billing_Detail__c> getBD() {
         return (List<Billing_Detail__c>) setCon.getRecords();
    }
    

	public List<Billing_Detail__c> listBD {get;set;}
	public String SelectedBdId {get;set;}
			
	public void loadData() {
		listBD = [Select Id,Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c   from Billing_Detail__c Where Monthly_Forecast__c=THIS_MONTH ];
	}

//to delete
	public void getDeleteBD(){
       listBD = [Select Id,Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c   from Billing_Detail__c Where Monthly_Forecast__c=THIS_MONTH AND id =:SelectedBdId];
      if(listBD.size() > 0 || listBD[0].Id != ''){
      delete listBD;
      }
      loadData();
  
   }
  
   
}
There is an error on vf page:
line 0 : Unknown method 'BDPaginationController.deleteBD()'
 Can you help me?

Thanks,
rank

 
Steven NsubugaSteven Nsubuga
Try this
public class BDPaginationController{
    Public Integer size{get;set;} 
    Public Integer noOfRecords{get; set;} 
    public List<SelectOption> paginationSizeOptions{get;set;}
         
    public BDPaginationController(){
        size=10;
        paginationSizeOptions = new List<SelectOption>();
        paginationSizeOptions.add(new SelectOption('5','5'));
        paginationSizeOptions.add(new SelectOption('10','10'));
        paginationSizeOptions.add(new SelectOption('20','20'));
        paginationSizeOptions.add(new SelectOption('50','50'));
        paginationSizeOptions.add(new SelectOption('100','100'));
    }
     
    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {                
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                      [Select Id,Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c   from Billing_Detail__c Where Monthly_Forecast__c=THIS_MONTH ]));
                setCon.setPageSize(size);  
                noOfRecords = setCon.getResultSize();
            }            
            return setCon;
        }
        set;
    }
     
    //Changes the size of pagination
    public PageReference refreshPageSize() {
         setCon.setPageSize(size);
         return null;
    }
 
    // Initialize setCon and return a list of record    
     
    public List<Billing_Detail__c> getBD() {
         return (List<Billing_Detail__c>) setCon.getRecords();
    }
    

	public List<Billing_Detail__c> listBD {get;set;}
	public String SelectedBdId {get;set;}
			
	public void loadData() {
		listBD = [Select Id,Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c   from Billing_Detail__c Where Monthly_Forecast__c=THIS_MONTH ];
	}

//to delete
	public PageReference deleteBD(){
       listBD = [Select Id,Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c   from Billing_Detail__c Where Monthly_Forecast__c=THIS_MONTH AND id =:SelectedBdId];
      if(listBD.size() > 0 || listBD[0].Id != ''){
      delete listBD;
      }
      loadData();
      return null;
   }
  
   
}

 
Akshay_DhimanAkshay_Dhiman
Hi Frank,

I reviewed your code You mistake in apex controller.

You used  public String BdId {get;set;}
insted of  public String SelectedBdId {get;set;} //  You used BdId in your VF page 
So change SelectedBdId by BdId.


 if you found this answer helpful then please mark it as best answer so it can help others.   
  
  Thanks 
  Akshay
Frank CarterFrank Carter
error on vf page:
Unknown property 'BDPaginationController.b'

I don't understand why.
Can you help me?

Thanks,
Frank
Steven NsubugaSteven Nsubuga
That is line 55 in your visualforce page. <apex:param value="{!b.Id}" name="idToDel" assignTo="{!SelectedBdId}"/>
That line is outside the pageblocktable in which b is defined. That is why you have that error.
Frank CarterFrank Carter
Ok, 
I put this :
<apex:commandLink action="{!deleteBD}" onclick="if(!confirm('Are you sure?')) return false;">Del
    			<apex:param value="{!b.Id}" name="idToDel" assignTo="{!SelectedBdId}"/>
						</apex:commandLink>
inside the pageblocktabland now No error.
The problem is when I click delete on a record.
it gave me the error:
The name can only contain underscores and alphanumeric characters. It must begin with a letter and be unique, and must not include spaces, end with an underscore, or contain two consecutive underscores. 

Why?
what am I doing wrong?


Thanks,
Frank
 
Frank CarterFrank Carter
The error appears when I click "del" on a record. 
User-added image

User-added image

name of the vf page: vfBilDet.vfp
Frank CarterFrank Carter
can someone help me??
Steven NsubugaSteven Nsubuga
public class BDPaginationController{
    Public Integer size{get;set;} 
    Public Integer noOfRecords{get; set;} 
    public List<SelectOption> paginationSizeOptions{get;set;}
         
    public BDPaginationController(){
        size=10;
        paginationSizeOptions = new List<SelectOption>();
        paginationSizeOptions.add(new SelectOption('5','5'));
        paginationSizeOptions.add(new SelectOption('10','10'));
        paginationSizeOptions.add(new SelectOption('20','20'));
        paginationSizeOptions.add(new SelectOption('50','50'));
        paginationSizeOptions.add(new SelectOption('100','100'));
    }
     
    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {                
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                      [Select Id,Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c   from Billing_Detail__c Where Monthly_Forecast__c=THIS_MONTH ]));
                setCon.setPageSize(size);  
                noOfRecords = setCon.getResultSize();
            }            
            return setCon;
        }
        set;
    }
     
    //Changes the size of pagination
    public PageReference refreshPageSize() {
         setCon.setPageSize(size);
         return null;
    }
 
    // Initialize setCon and return a list of record    
     
    public List<Billing_Detail__c> getBD() {
         return (List<Billing_Detail__c>) setCon.getRecords();
    }
    

	public List<Billing_Detail__c> listBD {get;set;}
	public String SelectedBdId {get;set;}
			
	public void loadData() {
		listBD = [Select Id,Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c   from Billing_Detail__c Where Monthly_Forecast__c=THIS_MONTH ];
	}

//to delete
	public PageReference deleteBD(){
      DELETE new Billing_Detail__c (Id = SelectedBdId);
      loadData();
      return null;
   }
  
   
}

Try that
Frank CarterFrank Carter
The same error. what could it be?

Thanks,
Frank
Steven NsubugaSteven Nsubuga
<apex:page controller="BDPaginationController" >
    <apex:form >
        <apex:actionFunction name="refreshPageSize" action="{!refreshPageSize}" status="fetchStatus" reRender="pbId"/>
        <apex:pageBlock id="pbId" title="Billing Details of this Month">
            <apex:pageBlockSection collapsible="false" columns="1">
                <apex:pageBlockTable value="{!BD}" var="b">
                    <apex:column >
                   <apex:outputLink title="" value="/{!b.Id}/e?retURL=/apex/{!$CurrentPage.Name}" style="font-weight:bold">Edit</apex:outputLink>&nbsp;|&nbsp;
					<a href="javascript&colon;if (window.confirm('Are you sure?')) DeleteBD'{!b.Id}');" style="font-weight:bold">Del</a>
					</apex:column>
					<apex:column value="{!b.Name}"/>
					<apex:column value="{!b.Billing_Type__c}"/>
					<apex:column value="{!b.Billing_Period__c}"/>    
					<apex:column value="{!b.Monthly_Forecast__c}"/>
					<apex:column value="{!b.End_of_Billing__c}"/>
					<apex:column value="{!b.Amount__c}"/>
					<apex:column value="{!b.Billing_Status__c}"/>
                    <apex:column >
                    <apex:commandLink action="{!deleteBD}" onclick="if(!confirm('Are you sure?')) return false;">Del <apex:param value="{!b.Id}" name="idToDel" assignTo="{!SelectedBdId}"/> </apex:commandLink>
                    </apex:column>
                </apex:pageBlockTable>
                 
                <apex:panelGrid columns="8"> 
                 
                <apex:selectList value="{!size}" multiselect="false" size="1" onchange="refreshPageSize();">
                    <apex:selectOptions value="{!paginationSizeOptions}"/>
                </apex:selectList>
                 
                <apex:commandButton status="fetchStatus" reRender="pbId" value="First" action="{!setCon.first}" disabled="{!!setCon.hasPrevious}" title="First Page"/> 
  
                <apex:commandButton status="fetchStatus" reRender="pbId" value="Previous" action="{!setCon.previous}" disabled="{!!setCon.hasPrevious}" title="Previous Page"/> 
  
                <apex:commandButton status="fetchStatus" reRender="pbId" value="Next" action="{!setCon.next}" disabled="{!!setCon.hasNext}" title="Next Page"/> 
  
                <apex:commandButton status="fetchStatus" reRender="pbId" value="Last" action="{!setCon.last}" disabled="{!!setCon.hasNext}" title="Last Page"/> 
  
                <apex:outputText >{!(setCon.pageNumber * size)+1-size}-{!IF((setCon.pageNumber * size)>noOfRecords, noOfRecords,
                     (setCon.pageNumber * size))} of {!noOfRecords}
                </apex:outputText> 
                       
                <apex:outputPanel >                      
                    <apex:actionStatus id="fetchStatus" >
                        <apex:facet name="start" >
                          <img src="/img/loading.gif" />                    
                        </apex:facet>
                    </apex:actionStatus>
                </apex:outputPanel> 
  
            </apex:panelGrid>  
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
 				<apex:commandButton value="Move to next month" action="!next"/>   
			</apex:pageBlockButtons>
        </apex:pageBlock>
        
        //aggiungo
         

        
        
    </apex:form>
</apex:page>
I hope you placed the commandlink inside a column as I have done above. .
Share your updated visualforce page if it is different from mine.
 
Frank CarterFrank Carter
The page is the same. It gaves me the same error

The name can only contain underscores and alphanumeric characters. It must begin with a letter and be unique, and must not include spaces, end with an underscore, or contain two consecutive underscores. 
Steven NsubugaSteven Nsubuga
Another shot
<apex:page controller="BDPaginationController" >
    <apex:form id="theform" >
        <apex:actionFunction name="refreshPageSize" action="{!refreshPageSize}" status="fetchStatus" reRender="pbId"/>
        <apex:pageBlock id="pbId" title="Billing Details of this Month">
            <apex:pageBlockSection collapsible="false" columns="1">
                <apex:pageBlockTable value="{!BD}" var="b">
                    <apex:column >
                   <apex:outputLink title="" value="/{!b.Id}/e?retURL=/apex/{!$CurrentPage.Name}" style="font-weight:bold">Edit</apex:outputLink>&nbsp;|&nbsp;
					<a href="javascript&colon;if (window.confirm('Are you sure?')) DeleteBD'{!b.Id}');" style="font-weight:bold">Del</a>
					</apex:column>
					<apex:column value="{!b.Name}"/>
					<apex:column value="{!b.Billing_Type__c}"/>
					<apex:column value="{!b.Billing_Period__c}"/>    
					<apex:column value="{!b.Monthly_Forecast__c}"/>
					<apex:column value="{!b.End_of_Billing__c}"/>
					<apex:column value="{!b.Amount__c}"/>
					<apex:column value="{!b.Billing_Status__c}"/>
                    <apex:column >
                    <apex:commandLink action="{!deleteBD}" onclick="if(!confirm('Are you sure?')) return false;" reRender="theform">Del <apex:param value="{!b.Id}" name="idToDel" assignTo="{!SelectedBdId}"/> </apex:commandLink>
                    </apex:column>
                </apex:pageBlockTable>
                 
                <apex:panelGrid columns="8"> 
                 
                <apex:selectList value="{!size}" multiselect="false" size="1" onchange="refreshPageSize();">
                    <apex:selectOptions value="{!paginationSizeOptions}"/>
                </apex:selectList>
                 
                <apex:commandButton status="fetchStatus" reRender="pbId" value="First" action="{!setCon.first}" disabled="{!!setCon.hasPrevious}" title="First Page"/> 
  
                <apex:commandButton status="fetchStatus" reRender="pbId" value="Previous" action="{!setCon.previous}" disabled="{!!setCon.hasPrevious}" title="Previous Page"/> 
  
                <apex:commandButton status="fetchStatus" reRender="pbId" value="Next" action="{!setCon.next}" disabled="{!!setCon.hasNext}" title="Next Page"/> 
  
                <apex:commandButton status="fetchStatus" reRender="pbId" value="Last" action="{!setCon.last}" disabled="{!!setCon.hasNext}" title="Last Page"/> 
  
                <apex:outputText >{!(setCon.pageNumber * size)+1-size}-{!IF((setCon.pageNumber * size)>noOfRecords, noOfRecords,
                     (setCon.pageNumber * size))} of {!noOfRecords}
                </apex:outputText> 
                       
                <apex:outputPanel >                      
                    <apex:actionStatus id="fetchStatus" >
                        <apex:facet name="start" >
                          <img src="/img/loading.gif" />                    
                        </apex:facet>
                    </apex:actionStatus>
                </apex:outputPanel> 
  
            </apex:panelGrid>  
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
 				<apex:commandButton value="Move to next month" action="!next"/>   
			</apex:pageBlockButtons>
        </apex:pageBlock>
        
    </apex:form>
</apex:page>
updated class
public class BDPaginationController{
    Public Integer size{get;set;} 
    Public Integer noOfRecords{get; set;} 
    public List<SelectOption> paginationSizeOptions{get;set;}
         
    public BDPaginationController(){
        size=10;
        paginationSizeOptions = new List<SelectOption>();
        paginationSizeOptions.add(new SelectOption('5','5'));
        paginationSizeOptions.add(new SelectOption('10','10'));
        paginationSizeOptions.add(new SelectOption('20','20'));
        paginationSizeOptions.add(new SelectOption('50','50'));
        paginationSizeOptions.add(new SelectOption('100','100'));
    }
     
    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {                
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                      [Select Id,Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c   from Billing_Detail__c Where Monthly_Forecast__c=THIS_MONTH ]));
                setCon.setPageSize(size);  
                noOfRecords = setCon.getResultSize();
            }            
            return setCon;
        }
        set;
    }
     
    //Changes the size of pagination
    public PageReference refreshPageSize() {
         setCon.setPageSize(size);
         return null;
    }
 
    // Initialize setCon and return a list of record    
     
    public List<Billing_Detail__c> getBD() {
         return (List<Billing_Detail__c>) setCon.getRecords();
    }
    

	public List<Billing_Detail__c> listBD {get;set;}
	public String SelectedBdId {get;set;}
			
	public void loadData() {
		listBD = [Select Id,Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c   from Billing_Detail__c Where Monthly_Forecast__c=THIS_MONTH ];
	}

//to delete
	public PageReference deleteBD(){
      DELETE new Billing_Detail__c (Id = SelectedBdId);
      return null;
   }
  
   
}


 
Frank CarterFrank Carter
Now I have a delete button on the right.
User-added image
but the page when the page refresh the record doesn't disappear. When I refresh User-added image
Frank CarterFrank Carter
ok with your last post I have again the delet button on the right. When I click it appears the pop up "are you sure?" but the page doesm't refresh. If I refresh the record disappeard
Steven NsubugaSteven Nsubuga
I added the reRender tag expecting it to use Ajax to reload the data without reloading the page.
Try this version of the controller.
public class BDPaginationController{
    Public Integer size{get;set;} 
    Public Integer noOfRecords{get; set;} 
    public List<SelectOption> paginationSizeOptions{get;set;}
         
    public BDPaginationController(){
        size=10;
        paginationSizeOptions = new List<SelectOption>();
        paginationSizeOptions.add(new SelectOption('5','5'));
        paginationSizeOptions.add(new SelectOption('10','10'));
        paginationSizeOptions.add(new SelectOption('20','20'));
        paginationSizeOptions.add(new SelectOption('50','50'));
        paginationSizeOptions.add(new SelectOption('100','100'));
    }
     
    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {                
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                      [Select Id,Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c   from Billing_Detail__c Where Monthly_Forecast__c=THIS_MONTH ]));
                setCon.setPageSize(size);  
                noOfRecords = setCon.getResultSize();
            }            
            return setCon;
        }
        set;
    }
     
    //Changes the size of pagination
    public PageReference refreshPageSize() {
         setCon.setPageSize(size);
         return null;
    }
 
    // Initialize setCon and return a list of record    
     
    public List<Billing_Detail__c> getBD() {
         return (List<Billing_Detail__c>) setCon.getRecords();
    }
    

	public List<Billing_Detail__c> listBD {get;set;}
	public String SelectedBdId {get;set;}
			
	public void loadData() {
		listBD = [Select Id,Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c   from Billing_Detail__c Where Monthly_Forecast__c=THIS_MONTH ];
	}

//to delete
	public void deleteBD(){
      DELETE new Billing_Detail__c (Id = SelectedBdId);
   }
  
   
}

 
Frank CarterFrank Carter
like it was before. to make it go away the record I have to reload the page.


Thanks,
Frank
Steven NsubugaSteven Nsubuga
Hm
public class BDPaginationController{
    Public Integer size{get;set;} 
    Public Integer noOfRecords{get; set;} 
    public List<SelectOption> paginationSizeOptions{get;set;}
         
    public BDPaginationController(){
        size=10;
        paginationSizeOptions = new List<SelectOption>();
        paginationSizeOptions.add(new SelectOption('5','5'));
        paginationSizeOptions.add(new SelectOption('10','10'));
        paginationSizeOptions.add(new SelectOption('20','20'));
        paginationSizeOptions.add(new SelectOption('50','50'));
        paginationSizeOptions.add(new SelectOption('100','100'));
    }
     
    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {                
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                      [Select Id,Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c   from Billing_Detail__c Where Monthly_Forecast__c=THIS_MONTH ]));
                setCon.setPageSize(size);  
                noOfRecords = setCon.getResultSize();
            }            
            return setCon;
        }
        set;
    }
     
    //Changes the size of pagination
    public PageReference refreshPageSize() {
         setCon.setPageSize(size);
         return null;
    }
 
    // Initialize setCon and return a list of record    
     
    public List<Billing_Detail__c> getBD() {
         return (List<Billing_Detail__c>) setCon.getRecords();
    }
    

	public List<Billing_Detail__c> listBD {get;set;}
	public String SelectedBdId {get;set;}
			
	public void loadData() {
		listBD = [Select Id,Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c   from Billing_Detail__c Where Monthly_Forecast__c=THIS_MONTH ];
	}

//to delete
	public void deleteBD(){
      DELETE new Billing_Detail__c (Id = SelectedBdId);
      loadData();
   }
  
   
}

 
Frank CarterFrank Carter
the same. to make it go away the record I have to reload the page. If this thing works I can remove the javascript delete button on the left and keep only the edit on the left?


Thanks,
Frank
Steven NsubugaSteven Nsubuga
This should work.
Controller
public class BDPaginationController{
    Public Integer size{get;set;} 
    Public Integer noOfRecords{get; set;} 
    public List<SelectOption> paginationSizeOptions{get;set;}
         
    public BDPaginationController(){
        size=10;
        paginationSizeOptions = new List<SelectOption>();
        paginationSizeOptions.add(new SelectOption('5','5'));
        paginationSizeOptions.add(new SelectOption('10','10'));
        paginationSizeOptions.add(new SelectOption('20','20'));
        paginationSizeOptions.add(new SelectOption('50','50'));
        paginationSizeOptions.add(new SelectOption('100','100'));
    }
     
    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {                
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                      [Select Id,Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c   from Billing_Detail__c Where Monthly_Forecast__c=THIS_MONTH ]));
                setCon.setPageSize(size);  
                noOfRecords = setCon.getResultSize();
            }            
            return setCon;
        }
        set;
    }
     
    //Changes the size of pagination
    public PageReference refreshPageSize() {
         setCon.setPageSize(size);
         return null;
    }
 
    // Initialize setCon and return a list of record    
     
    public List<Billing_Detail__c> getBD() {
         return (List<Billing_Detail__c>) setCon.getRecords();
    }
    

    public List<Billing_Detail__c> listBD {get;set;}
    public String SelectedBdId {get;set;}
            
    public void loadData() {
        listBD = [Select Id,Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c   from Billing_Detail__c Where Monthly_Forecast__c=THIS_MONTH ];
    }

//to delete
    public PageReference deleteBD(){
      DELETE new Billing_Detail__c (Id = SelectedBdId);
      return null;
   }
  
   
}

Page
<apex:page controller="BDPaginationController" >
    <apex:form id="theform" >
        <apex:actionFunction name="refreshPageSize" action="{!refreshPageSize}" status="fetchStatus" reRender="pbId"/>
        <apex:pageBlock id="pbId" title="Billing Details of this Month">
            <apex:pageBlockSection collapsible="false" columns="1">
                <apex:pageBlockTable value="{!BD}" var="b">
                    <apex:column >
                   <apex:outputLink title="" value="/{!b.Id}/e?retURL=/apex/{!$CurrentPage.Name}" style="font-weight:bold">Edit</apex:outputLink>&nbsp;|&nbsp;
                    <apex:commandLink style="font-weight:bold" action="{!deleteBD}" onclick="if(!confirm('Are you sure?')) return false;" >Del <apex:param value="{!b.Id}" name="idToDel" assignTo="{!SelectedBdId}"/> </apex:commandLink>
                    </apex:column>
                    <apex:column value="{!b.Name}"/>
                    <apex:column value="{!b.Billing_Type__c}"/>
                    <apex:column value="{!b.Billing_Period__c}"/>    
                    <apex:column value="{!b.Monthly_Forecast__c}"/>
                    <apex:column value="{!b.End_of_Billing__c}"/>
                    <apex:column value="{!b.Amount__c}"/>
                    <apex:column value="{!b.Billing_Status__c}"/>
                    
                </apex:pageBlockTable>
                 
                <apex:panelGrid columns="8"> 
                 
                <apex:selectList value="{!size}" multiselect="false" size="1" onchange="refreshPageSize();">
                    <apex:selectOptions value="{!paginationSizeOptions}"/>
                </apex:selectList>
                 
                <apex:commandButton status="fetchStatus" reRender="pbId" value="First" action="{!setCon.first}" disabled="{!!setCon.hasPrevious}" title="First Page"/> 
  
                <apex:commandButton status="fetchStatus" reRender="pbId" value="Previous" action="{!setCon.previous}" disabled="{!!setCon.hasPrevious}" title="Previous Page"/> 
  
                <apex:commandButton status="fetchStatus" reRender="pbId" value="Next" action="{!setCon.next}" disabled="{!!setCon.hasNext}" title="Next Page"/> 
  
                <apex:commandButton status="fetchStatus" reRender="pbId" value="Last" action="{!setCon.last}" disabled="{!!setCon.hasNext}" title="Last Page"/> 
  
                <apex:outputText >{!(setCon.pageNumber * size)+1-size}-{!IF((setCon.pageNumber * size)>noOfRecords, noOfRecords,
                     (setCon.pageNumber * size))} of {!noOfRecords}
                </apex:outputText> 
                       
                <apex:outputPanel >                      
                    <apex:actionStatus id="fetchStatus" >
                        <apex:facet name="start" >
                          <img src="/img/loading.gif" />                    
                        </apex:facet>
                    </apex:actionStatus>
                </apex:outputPanel> 
  
            </apex:panelGrid>  
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
                <apex:commandButton value="Move to next month" action="!next"/>   
            </apex:pageBlockButtons>
        </apex:pageBlock>
        
    </apex:form>
</apex:page>

 
This was selected as the best answer
Frank CarterFrank Carter
the rerender starts but the record don't go away if I reload the page it gaves me this error:

Delete failed. First exception on row 0 with id a015800000qeppgAAA; first error: ENTITY_IS_DELETED, entity is deleted: []
Error is in expression '{!deleteBD}' in page vfbildet: Class.BDPaginationController.deleteBD: line 51, column 1
An unexpected error has occurred. Your development organization has been notified.


if I click back I have the list without that eliminated

thanks Frank
Steven NsubugaSteven Nsubuga
Think I found the issue, here is the updated controller.
public class BDPaginationController{
    Public Integer size{get;set;} 
    Public Integer noOfRecords{get; set;} 
    public List<SelectOption> paginationSizeOptions{get;set;}
         
    public BDPaginationController(){
        size=10;
        paginationSizeOptions = new List<SelectOption>();
        paginationSizeOptions.add(new SelectOption('5','5'));
        paginationSizeOptions.add(new SelectOption('10','10'));
        paginationSizeOptions.add(new SelectOption('20','20'));
        paginationSizeOptions.add(new SelectOption('50','50'));
        paginationSizeOptions.add(new SelectOption('100','100'));
    }
     
    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {                
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                      [Select Id,Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c   from Billing_Detail__c Where Monthly_Forecast__c=THIS_MONTH ]));
                setCon.setPageSize(size);  
                noOfRecords = setCon.getResultSize();
            }            
            return setCon;
        }
        set;
    }
     
    //Changes the size of pagination
    public PageReference refreshPageSize() {
         setCon.setPageSize(size);
         return null;
    }
 
    // Initialize setCon and return a list of record    
     
    public List<Billing_Detail__c> getBD() {
         return (List<Billing_Detail__c>) setCon.getRecords();
    }
    

    public List<Billing_Detail__c> listBD {get;set;}
    public String SelectedBdId {get;set;}
            
    public void loadData() {
        listBD = [Select Id,Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c   from Billing_Detail__c Where Monthly_Forecast__c=THIS_MONTH ];
    }

//to delete
    public PageReference deleteBD(){
      DELETE new Billing_Detail__c (Id = SelectedBdId);
      PageReference pageRef = ApexPages.currentPage();
      pageRef.setRedirect(true);
      return pageRef;
   }
  
   
}

 
Frank CarterFrank Carter
now it works perfectly.

tank you very much, you are the best.
Steven NsubugaSteven Nsubuga
Took us quite a while, it was my pleasure!!
Ajay K DubediAjay K Dubedi
Hi Frank,

Please try this changes in your controller.

1-you can use this replace SelectedBdId to BdId.
  public String BdId {get;set;}
  
2- For method-
    <apex:param value="{!b.Id}" name="idToDel" assignTo="{!BdId}"/>

    public PageReference deleteBD(){               
           public PageReference deleteBD(){
           BdId = ApexPages.currentPage().getParameters().get('idToDel');
          listBD = [Select Id,Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c   from Billing_Detail__c Where Monthly_Forecast__c=THIS_MONTH AND id =:BdId];
          if(listBD.size() > 0 || listBD[0].Id != ''){
          delete listBD;
          }
          loadData();
          pagereference ref =new pagereference('/apex/Your VF page Name');//your VFPage Name
                   ref.setredirect(true);
                   return ref;
       }

Please let me know if you have any query.
Please mark it as best Answer if you find it helpful.

Thank You
Ajay Dubedi