You need to sign in to do that
Don't have an account?
etechcareers
How to return/display error message when no records are found???
Hi:
When no records are found in my search result I need to return a message to the user on the page No records were found...Here is my code for it.. As you see I tried to do it but nuthing happens...Someone please help..
public List<Account> getResults() { return this.results; } public PageReference doSearch() { results = (List<Account>) [FIND :searchText IN NAME FIELDS RETURNING Account(Name,BillingState,BillingCity,Phone,Website,Id,RecordType.Name)] [0]; if(results==null){ ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'No Records found')); } return null; }
Did you add a messages tag to the visualforce page?
I believe that is required for displaying the messages from controllers outside of the debug log.
public PageReference doSearch() {
results = (List<Account>)
[FIND :searchText IN NAME FIELDS RETURNING Account(Name,BillingState,BillingCity,Phone,Website,Id,RecordType.Name)] [0];
if(results==null){
ApexPages.Message errormessage = new ApexPages.Message(ApexPages.Severity.ERROR,'No Records found');
ApexPages.addMessage(errormessage);
}
return null
try this.