You need to sign in to do that
Don't have an account?
Frank 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:
and the controller code is:
I have 2 errors on developer console:
Thanks,
Frank
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> | <a href="javascript: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
Thanks,
Frank
Controller
Page
All Answers
I upgraded the code with your and I passed the value in VF (line 55): controller: There is an error on vf page:
line 0 : Unknown method 'BDPaginationController.deleteBD()'
Can you help me?
Thanks,
rank
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
Unknown property 'BDPaginationController.b'
I don't understand why.
Can you help me?
Thanks,
Frank
That line is outside the pageblocktable in which b is defined. That is why you have that error.
I put this : 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
name of the vf page: vfBilDet.vfp
Try that
Thanks,
Frank
Share your updated visualforce page if it is different from mine.
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.
but the page when the page refresh the record doesn't disappear. When I refresh
Try this version of the controller.
Thanks,
Frank
Thanks,
Frank
Controller
Page
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
tank you very much, you are the best.
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