You need to sign in to do that
Don't have an account?
<apex:message> how to get it to work for specific fields?
Hi i was wondering could someone give me an example on how to get <apex:message> to work, for example i have field called contact name and want the error to be shown on that field.
if(!IsDuplicateLink()) { insert s; } else { Account dupe = [SELECT Id, Name FROM Account WHERE Id = :eId]; ApexPages.Message dupeMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Contact already exists in ' + dupe.Name); ApexPages.addMessage(dupeMsg); drawError = true; } <apex:message for="conName"/> <apex:inputField id="conName" value="{!Contact.Name}"/>
for some reason this does not work?
for (Account a : Trigger.new) { if (a.name == 'bad') { a.name.addError('Bad name'); //will add an error to the account NAME field } }
Ah, you want it to work for underlying validation rules...
That, I have not done before. I would be curious to see how that is done.
Hi...
Try this link
http://salesforcesource.blogspot.com/2008/09/how-do-custom-validations-in-visual.html
If I understand what you are asking, where you asked, "I am also having problems where i want my standard validation rules which are shown most at the field level, to be shown in my custom visualforce page?", and you are using a standard controller, it should just work without using apex:message. From the developer guide,
If a user enters data on a Visualforce page that uses a standard controller, and that data causes a validation rule error, the error can be displayed on the Visualforcepage. If the validation rule error location is a field associated with an <apex:inputField> component, the error displays there. If the validation rule error location is set to the top of the page, use the <apex:pageMessages> or <apex:messages> component within the <apex:page> to display the error.
If you are using a custom controller, it's a bit harder. You have to catch the error in your controller. See http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_validation.htm
For the new ApexPages.Message object that is passed to the addMessage() method, how would a person associate the message with a particular field back on the VF page? I assume this needs to be done to display the error message with the appropriate <apex:message> component. I see that there is a Message.getComponentLabel() method, but I do not see in the docs a Message.setComponentLabel() method or a way to pass that to the ApexPages.Message contructor.
thanks,
Chris
I also have a problem to see apex:messages on Vf when using extensions and rendering action status:
VF:
<apex:page standardController="Object__c" extensions="CustumController" ><apex:messages />
<apex:pageBlock title="Data" >
<apex:pageBlockButtons >
<apex:commandButton value="Do something" action="{!DoSomething}" rerender="status" status="Status" />
</apex:pageBlockButtons>
<apex:actionStatus id="Status" startText="I'm doing something">
<apex:facet name="start">
<apex:outputtext > I'm doing something</apex:outputtext>
</apex:facet>
<apex:facet name="stop">
</apex:facet>
</apex:actionStatus>