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

Field Message just doesn't work. Help!

Hi There.


I want to copy the standard behavior of field validation error on a visual force page.


here is my prototype:



<apex:page controller="Test">
    <apex:form > 
        <apex:pageBlock title="Hello {!$User.FirstName}!">
		<apex:inputtext value="{!ola}" id="e_validation"/> 
        <apex:commandButton action="{!save}" value="Save"/>    
        <apex:message for="e_validation"  />   

 And the controller:

public with sharing class Test {
	public String ola {get;set;}
	public PageReference save(){
		ApexPages.addmessage(new ApexPages.message(ApexPages.Severity.ERROR,'test'));
		return null;


Nothing happens when I click on save button. I expect that message 'test' appears bellow the inputtext component on visual page : (

Best Answer chosen by Admin (Salesforce Developers) 

That's how apex:message is supposed to work I'm afraid.


I wrote a blog post that I think covers exactly what you are looking for at:

All Answers


That's how apex:message is supposed to work I'm afraid.


I wrote a blog post that I think covers exactly what you are looking for at:

This was selected as the best answer

Thanks for your fast reply.


Apart of  your very useful blog, can you tell me:


1. if this documentation example works:



2. Do you have an idea how to send the message to an inputfield in the current page when the adderror() has to be called from a trigger on the child object?


With this line, I cancel the transaction and a message is placed on the top of the current page:


childobject.addError('Error: Field content is invalid');


I tried this:


childobject.parent__r.field__c.addError('Error: Field content is invalid');


and this


parentObject = [select field__c from parentObject__c where id = :childobject.parent__c];

parentObject.field__c.addError('Error: Field content is invalid');


both resulting in messages on top of the page.


Let me know if you need further detail to check this issue.


Thnaks in advance.







i dont know if it helps but try adderror..







If y read my code that is what I have done :smileywink:


1. That does work, but it just puts coloured messages at the bottom of the page I think.


2.  I'm not sure how easy its going to be to add an error to a field from that trigger.    I'd expect the error needs to be added to the object + field combo that is present on the page.  At the point that the trigger fires, you don't have access to that object instance.  Querying another one back and adding errors is unlikely to help.  Can you post a bit more detail about the scenario.




1: So it is not expected that it puts some message at field level, i.e., below the visualforce connected to the field. : (


2. For now I am throwing a custom exception from the trigger so I can catch it on the controller and I can do 




However I am facing a liitle problem:


At the top of the page are appearing both messages which seems be natural once i am adding errors to the object.


I would want to setup different independent messages for top page and for field level but I think it demands another type of customization. Some ideas?


1. I don't think I had an expectation when I tried it.  I didn't find it useful though, which is why I spent some time trying to understand how all that works.


2. Are you putting the errors at the top of the page using apex:pageMessages?  if so, I think that does duplicate it.


We've used our own error div at the top of the page and simply added items to a string that gets output inside that div.


yeah. The use of a div or something is the kind of customization I was talking about.


For now  It will stays this way. I am checking deeply your blog later so I can purpose an alternative customized solution. Meanwhile tanks very much for your support.