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
aditervaditerv 

modify Apex pageMessages before displaying on VF pages

Hi,

 

We have added some validation rules to some of the fields. But when any validation fails, that error message gets displayed at the top of VF page with appended field lables at the start of error message.

 

For e.g If validation error message is added as Is manadatory then the error message displays that like Name: is manadation where Name is the field lable.

I want to remove this field lable from being appended to message, any help to edit these page messages before displaying on VF.

 

Thanks.

Puja_mfsiPuja_mfsi

Hi,

You need to add server side validation.as:

if( variable != null && variable.length() > 0 ) {

            ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Put uor msg here');

            ApexPages.addmessage(myMsg);

}

and remove the required=true from VF,in case of required attribute.

 

Please let me know if u have any problem on same and if this post helps u then plz give KUDOS by click on star at left.

aditervaditerv

Thanks for your reply.

But we do not want to hard code the message like this. Error message is already put while adding  Validation rules for object. We want that when those messages gets displayed on VF page, it should be editable so taht we can remove the field lable from them.

We are not sure how to edir apes:pageMessages which is doing this.

Puja_mfsiPuja_mfsi

Hi,

I don't think there is any way to edit VF page messages.

 

Please let me know if u have any problem on same and if this post helps u then plz give KUDOS by click on star at left.

aditervaditerv
Thanks, but we are searching for any tag which can give us access to these error messages so that we can edit them. As we do not want field lable to display in message but salesforce automatically appends that in every message.
Sgt_KillerSgt_Killer

Try adding an output text field at the top of the form and assign the error message to a string. Use some string methods to eliminate the field label from the message and display it using the output text.

aditervaditerv
Thanks.
I am getting error messages in <apex:pageMessages> tag.
How can I assign pageMessages to a string?
Can you please explain the same.
Sgt_KillerSgt_Killer

It would be helpful if you could post the vf code and the save method in your controller.

sandeep@Salesforcesandeep@Salesforce

You can avoid this happing as you pass  exception instance "e" as below :-

 

Try{

 

}Catch(Exception e)

{

ApexPages.addMessages(e);

}

 

Adds a list of messages to the current page context based on a thrown exception.