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
Ram P 40Ram P 40 

Visualforce page on Contact

I want to create a VF page on Contact..with fields FirstName,LastName,Phone,Email..I want to fire a validation LastName not more than 10 characters..morethan 10 mwans i want to display an error message.."character limit was reached"
Steven NsubugaSteven Nsubuga
User-added image
Raj VakatiRaj Vakati
Here is the visualforce page 
 
<apex:page sidebar="false" standardController="Contact">

<apex:form>
    <apex:pageBlock title="My Content" mode="edit">
      <apex:pageBlockButtons>
        <apex:commandButton action="{!save}" value="Save"/>
      </apex:pageBlockButtons>
      <apex:pageBlockSection title="My Content Section" columns="2">
        <apex:inputField value="{!Contact.FirstName}"/>
        <apex:inputField value="{!Contact.LastName}"/>
        <apex:inputField value="{!Contact.Email}"/>
        <apex:inputField value="{!Contact.Phone}"/>
      </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>
  
  
</apex:page>



And use the validation rule whihc Steven Nsubuga shared ... 
Ram P 40Ram P 40
Hii Raj thanks for your Response..
       for that visualforce page i want to write apex class also.. and one more thing I asked Cancel button also??
Ram P 40Ram P 40
Raj how can we write that validation in Apex class  which is LastName not more than 10 characters?? 
Raj VakatiRaj Vakati
You dnt need apex class for this
 
<apex:page sidebar="false" standardController="Contact">

<apex:form>
    <apex:pageBlock title="My Content" mode="edit">
      <apex:pageBlockButtons>
        <apex:commandButton action="{!save}" value="Save"/>
        <apex:commandButton action="{!cancel}" value="Cancel"/>

      </apex:pageBlockButtons>
      <apex:pageBlockSection title="My Content Section" columns="2">
        <apex:inputField value="{!Contact.FirstName}"/>
        <apex:inputField value="{!Contact.LastName}"/>
        <apex:inputField value="{!Contact.Email}"/>
        <apex:inputField value="{!Contact.Phone}"/>
      </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>
  
  
</apex:page>

 
Ram P 40Ram P 40
thanks Raj & Steven Nsubuga