0

I have a page that filter records based on a field, when a user search for a record that do not exist the following error page is displayed

I want to display a customized error like "record does not exist" in the current visualforce page.

1

Do a check on the list you get from your Select query if its size is 0 and add an Apex Message. I hope your method in controller is returning PageReference.

if(myList.size() == 0){
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Query returned zero records!');
ApexPages.addMessage(myMsg);
return null;
}

In your Visualforce page, add a tag

<apex:pageMessages id="msgs" />

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.