Reply
Regular Contributor
stunaite
Posts: 47
0
Accepted Solution

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:

 

Page:

<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"  />   
        </apex:pageBlock>  
    </apex:form>  
</apex:page

 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 : (

Moderator
bob_buzzard
Posts: 6,427
0

Re: Field Message just doesn't work. Help!

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:

 

http://bobbuzzard.blogspot.com/2011/04/field-level-error-messages-with_29.html

--
Certified Salesforce Technical Architect, Developer, Advanced Developer, Administrator, Advanced Administrator, Consultant, Sales Cloud Consultant,Service Cloud Consultant
Force.com MVP | The Bob Buzzard Blog | Linked In | Twitter

I don't respond to private messages/emails asking for help.


Take the Bob Buzzard Sobject Fields quiz.

Regular Contributor
stunaite
Posts: 47
0

Re: Field Message just doesn't work. Help!

Thanks for your fast reply.

 

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

 

1. if this documentation example works:

 

http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_message.htm

 

 

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.

 

 

 

 

 

Regular Contributor
sssssss
Posts: 20
0

Re: Field Message just doesn't work. Help!

i dont know if it helps but try adderror..

 

 

 

 

 

Regular Contributor
stunaite
Posts: 47
0

Re: Field Message just doesn't work. Help!

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

Moderator
bob_buzzard
Posts: 6,427
0

Re: Field Message just doesn't work. Help!

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.

--
Certified Salesforce Technical Architect, Developer, Advanced Developer, Administrator, Advanced Administrator, Consultant, Sales Cloud Consultant,Service Cloud Consultant
Force.com MVP | The Bob Buzzard Blog | Linked In | Twitter

I don't respond to private messages/emails asking for help.


Take the Bob Buzzard Sobject Fields quiz.

Regular Contributor
stunaite
Posts: 47
0

Re: Field Message just doesn't work. Help!

Hi.

 

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 

soBj.adderror('MyErrorStringTopofThepage');

soBj.field.adderror('MyErrorStringFieldLevel');

 

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?

Moderator
bob_buzzard
Posts: 6,427
0

Re: Field Message just doesn't work. Help!

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.

--
Certified Salesforce Technical Architect, Developer, Advanced Developer, Administrator, Advanced Administrator, Consultant, Sales Cloud Consultant,Service Cloud Consultant
Force.com MVP | The Bob Buzzard Blog | Linked In | Twitter

I don't respond to private messages/emails asking for help.


Take the Bob Buzzard Sobject Fields quiz.

Regular Contributor
stunaite
Posts: 47
0

Re: Field Message just doesn't work. Help!

[ Edited ]

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.

 

Regards