Skip to main content
How can i throw error msg via apex if i have a field name birthdate in vf page and if birthdate is less than 18 years it throw error while i am saving record ..

Can somenone please help.

Thanks,

 
3 answers
  1. Apr 1, 2021, 5:58 AM
    Hi Amit,

    Greetings!

    Apex:-

    if (birthdate  < 18)

    {

        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Your Error Message'));

        return null;

    }

     

    Vf Page- 

    add this tag in VF Code

    <apex:pageMessages ></apex:pageMessages>

    Please mark it as the best answer if it helps you to fix the issue.

    Thank you!

    Regards,

    Malika Pathak
0/9000