You need to sign in to do that
Don't have an account?

Action function - Error : The name can only contain underscores and alphanumeric characters
Hi All - I am adding the action function in my visualforce page. I want to invoke an method from my controller on the onblur of the attribute. I get the following error, When I preview the visualforce page : 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.
Visualforce page code
------------------------------
<apex:page standardController="AccountLocation__c" extensions="AccountLocationEditController" recordSetVar="AccountLocation__c" >
<script>
function javaScript(){
location();
}
</script>
<apex:form>
<apex:actionFunction name="location" action="{!location}" rerender="loc"/>
<apex:param name="firstParam" assignTo="{!AccLoc.Name}" value="Bill To" />
<apex:pageBlock title="Account Location Edit" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save"/>
<apex:commandButton action="{!savenew}" value="Save & New"/>
<apex:commandButton action="{!Cancel}" value="Cancel"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Information" columns="2">
<apex:inputField value="{!AccLoc.Type__c}" required="true" onblur="javaScrpt()" />
<apex:inputField value="{!AccLoc.AccountId__c}" />
<apex:inputField id = "loc" value="{!AccLoc.Name}" />
</apex:pageBlockSection>
Controller Code
-------------------
public with sharing class AccountLocationEditController{
Public AccountLocation__c AccLoc {get;set;}
/*ApexPages.StandardController Controller = null;*/
public AccountLocationEditController(ApexPages.StandardSetController stdController) {
AccLoc = new AccountLocation__c ();
Id strId= ApexPages.currentPage().getParameters().get('id');
/* if (strId!=null){
AccLoc = [SELECT Id, Name,Type__c
FROM AccountLocation__c
WHERE Id = :strId];
}*/
system.debug('loc name' +AccLoc.Name);
}
Public PageReference location(){
if (AccLoc.Type__c == 'Bill TO'){
AccLoc.Name = 'Bill To Address';
system.debug('loc name' +AccLoc.Name);
}else {
AccLoc.Name = 'Ship To Address';
}
return null;
}
Please let me know if I had missed anything. Thanks you in Advance !
Visualforce page code
------------------------------
<apex:page standardController="AccountLocation__c" extensions="AccountLocationEditController" recordSetVar="AccountLocation__c" >
<script>
function javaScript(){
location();
}
</script>
<apex:form>
<apex:actionFunction name="location" action="{!location}" rerender="loc"/>
<apex:param name="firstParam" assignTo="{!AccLoc.Name}" value="Bill To" />
<apex:pageBlock title="Account Location Edit" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save"/>
<apex:commandButton action="{!savenew}" value="Save & New"/>
<apex:commandButton action="{!Cancel}" value="Cancel"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Information" columns="2">
<apex:inputField value="{!AccLoc.Type__c}" required="true" onblur="javaScrpt()" />
<apex:inputField value="{!AccLoc.AccountId__c}" />
<apex:inputField id = "loc" value="{!AccLoc.Name}" />
</apex:pageBlockSection>
Controller Code
-------------------
public with sharing class AccountLocationEditController{
Public AccountLocation__c AccLoc {get;set;}
/*ApexPages.StandardController Controller = null;*/
public AccountLocationEditController(ApexPages.StandardSetController stdController) {
AccLoc = new AccountLocation__c ();
Id strId= ApexPages.currentPage().getParameters().get('id');
/* if (strId!=null){
AccLoc = [SELECT Id, Name,Type__c
FROM AccountLocation__c
WHERE Id = :strId];
}*/
system.debug('loc name' +AccLoc.Name);
}
Public PageReference location(){
if (AccLoc.Type__c == 'Bill TO'){
AccLoc.Name = 'Bill To Address';
system.debug('loc name' +AccLoc.Name);
}else {
AccLoc.Name = 'Ship To Address';
}
return null;
}
Please let me know if I had missed anything. Thanks you in Advance !
AccLoc = new AccountLocation__c ();
updated to AccountLocation__c AccLoc = new AccountLocation__c . Issue was resolved.
All Answers
I see a typo in the name of the function that needs to be called on the onblur event of <apex:inputField>. Update the below line of code
to the below code and this should address your issue.
One other thing to remember is to avoid usage of keywords as function names that are already reserved for Apex, Visualforce or Javascript within your code which could lead to issues. For e.g. rename the javaScript function to something more meaningful that defines the purpose of the function and is inuitive for e.g. findLocation() or getLocation().
Please mark the thread as SOLVED and answer as the BEST ANSWER if it helps address your issue.
THanks,
Sujatha.M
Thanks,
Sujatha.M
Can you share the generated Debug Log to get details around the exact point of failure?
AccLoc = new AccountLocation__c ();
updated to AccountLocation__c AccLoc = new AccountLocation__c . Issue was resolved.