Sunday, August 3, 2014

How to make Field as Required in Visualforce page?

How to make Field as Required in Visualforce page?

In this post i am giving a simple visualforce example of making a not-required field as required in Visualforce Page.

Visualforce Page:
<apex:page standardController="Account">
<apex:form >
 <apex:pageBlock >
   <apex:pageblocksection title="Account Information">
    <apex:inputfield value="{!account.Name}"/>
    <apex:inputField value="{!account.AccountNumber}"/>    
       <apex:inputfield value="{!account.AccountNumber}" required="true"/>
 <apex:pageblockButtons >
<apex:commandButton value="Save" action="{!save}"/>  

Output :

if you observe in the standard page layout the account-number is not required field on account object. i maed it as required in visualforce page with the 
 <apex:inputfield value="{!account.AccountNumber}" required="true"/> tag.

save image

in Visualforce page if you try to save the record with out enter any value in Account Number field it is showing the error message 

save image

That's it ...
Thanks for reading........


Post a Comment

| ,