I am calling apex class method from vf page using actionFunction, but it is not working because on my page i am having mandatory fields, so i want that their an error should be shown like "please fill mandatory fields first", so how can i do this...

<apex:page standardController="Contract__c" extensions="ContractNew">
       <apex:actionFunction name="checkContract" action="{!checkContract}" reRender="stuf"/>
      <apex:inputField value="{!Acn.Account__c}" />   <!--   this field is mandatory  
      <apex:inputField value="{!Acn.Contract_Type__c}" onchange="checkContract()"/>

Apex method:

Public void checkContract(){
    if(Acn.Contract_Type__c == 'x ' || Acn.Contract_Type__c == 'y'){
                        stuf1Render = stuf2Render = true;

  • Have you tried action region? – SFIntegrator Jun 5 '15 at 10:48

On top of your visualforce page add,



This component displays all messages that were generated for all components on the current page, presented using the Salesforce styling. This will capture the error messages and show it on top of the page.

Please refer the Salesforce Documentation.

  • If the answer helps you solve your problem, mark it as accepted and upvote it so that other fellow users can get benefit from it. Thanks – Vigneshwaran G Jun 5 '15 at 10:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.