1

I've this simple VF page, which is populating today's date on change of value of Picklist(Active__c field as mentioned below): This is done with help of action function which refreshes an outputText. But it is not working. its gives error : Visualforce Error Help for this 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. Does using extention anything to do with it?

<apex:page standardcontroller="Account" extensions="RefeshCon">

  <script type = "Text/Javascript">
  function PopulateDate()
  { 
    alert('hi');
   ActPopulateDate();
  }
  </script>
  <apex:form > 
    <apex:ActionFunction name="ActPopulateDate" action="{!populatedateviaCont}" reRender="Refreshdate" />
    <apex:pageblock >
     <apex:pageblockSection >
       <apex:inputField value="{!Account.Name}" />
       <apex:inputField value="{!Account.Active__c}" onchange="PopulateDate()" />
       <apex:outputText value="{!d}" id="Refreshdate" />
     </apex:pageblockSection>
    </apex:pageblock>
  </apex:form> 
</apex:page>

This is my controller

public class RefeshCon {

    public datetime d {get;set;}

    public RefeshCon(ApexPages.StandardController controller) {
    }
    public pagereference populatedateviaCont() {
        d = system.now();
        return null;
    }
}
1
  • Is the page not working at all, or only when you change the input field? What is the name of your visualforce page?
    – CyberJus
    Apr 5, 2015 at 3:10

1 Answer 1

1

As I understand your problem, Picklist Active__c field gets updated with today's date whenever there's any activity on in the account. From the error message you're getting, it sounds like Active__c is text field.

 <apex:pageblockSection >
   <apex:inputField value="{!Account.Name}" />
   <apex:inputField value="{!Account.Active__c}" onchange="PopulateDate()" />
   <apex:outputText value="{!d}" id="Refreshdate" />

That means when you run the code below, you need to get the string value of the DateTime using string.valueOf() on system.now() as shown below. System.now()is a datetime field and will include the date, as well as time including minutes, seconds, time zone, etc. :

public string d {set;} // you only need to set this value, not get it too

public pagereference populatedateviaCont() {
    d = string.valueOf(System.now()); 
    return null;
}

You must log in to answer this question.

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