Years ago I wrote a VF page and a controller class to edit all contacts of an agreement in one form. The user can select contacts, their role and set a primary contact. If user clicks submit button some lines of Javascript/JQuery store all values as JSON string in a hidden field. The controller class just needs this JSON string to change the list of contacts.

Edit Contact Roles 1 Edit Contact Roles 2

That worked even with Lightning. Since some months I get an error message when clicking the add button to add one or more empty dropdowns (for lookup popup) for new contacts. The form is used not often, so I cannot say how long this error occurs. The message says:

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.

First I guessed some variable name in my code is wrong, but I didn't change the code this year.

But maybe it is a wrong filename like in this question: https://trailblazers.salesforce.com/answers?id=9063A000000lOWxQAM Name of VF page is edit_contact_roles.page, controller class is EditContactRoles.cls and ContactRoleCRItem.cls for a helper class which only holds some data for each contact. JQuery is included with:

<script src="{!URLFOR($Resource.PBSI__jQuery_1_8_2,'')}" />

Biggest problem is that the error only occurs in production, I cannot reproduce it in sandbox, I deployed current sandbox code to production, but the error still occurs.

Does anyone knows what this message means and how to fix it?

Buttons on VF page:

<apex:selectList value="{!nrows}" size="1">
    <apex:selectOptions value="{!items}"/>
<apex:commandButton value="Add Rows" action="{!addRows}" />
<apex:commandButton value="cancel" action="{!cancel}" />
<apex:commandButton value="Submit" action="{!submit}" id="submitCRForm"/>

Controller code for add button creates n new contact items:

public PageReference addRows() {
        PageReference nextPage = new PageReference('/apex/edit_contact_roles/?pageId=' + this.pageId);
        return null;    
    private void addNewContactRoles() {
        if (this.formData != null && this.formData != '') {
            this.contactRolesList = (List<ContactRoleCRItem>) System.JSON.deserialize(this.formData, List<ContactRoleCRItem>.class);
        if (this.nrows == null || this.nrows == 0) {
            this.nrows = 1;
        Boolean isPrimary = (this.contactRolesList.size() == 0);
        for (Integer i = 0; i < this.nrows; i++) {
            this.contactRolesList.add(new ContactRoleCRItem(ID_NULL, isPrimary, ID_NULL, '', '', false));   
            isPrimary = false;

Helper class ContactRoleCRItem just holds some data for each contact and has no logic.

  • Can you post the code for Add Rows button. I suspect the VF page url might not be forming well. Also can you paste a screenshot of the page name ? Or right click and press inspect element (chrome) to check what is the VFPage url being formed. And share a screenshot. Nov 19, 2020 at 2:09
  • added some code and screenshot
    – Obi_77
    Nov 19, 2020 at 23:27
  • Can uou try changing this PageReference nextPage = new PageReference('/apex/edit_contact_roles/?pageId=' + this.pageId); to PageReference nextPage = new PageReference('/apex/edit_contact_roles?pageId=' + this.pageId);. Also, when you click addRows, the network tab in chrome will show the VF page url being formed, can you share that too? Nov 19, 2020 at 23:49
  • I changed the PageReference from edit_contact_roles/?pageId= to edit_contact_roles?pageId= and deployed it. But error still occurs in production, sandbox works. The Javascript warning occurs on several Salesforce apges and seems not to be related to my code.
    – Obi_77
    Nov 20, 2020 at 9:34
  • Ok give another try by removing the page params from ? and add it via pageRef.getParameters().put('Key', 'Value'); or if possible can you try with a page with no underscore at all. Nov 20, 2020 at 9:51

1 Answer 1


So with trial and error we came up with an answer to change the page name without any underscore and it worked.

Not sure though why page name with underscore worked in sandbox and not in production. (If anyone has an explanationto this do comment it.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .