You need to sign in to do that
Don't have an account?
How to display a message if no records are returned from a SOQL query?
I have a simple VF page that calls a custom controller to retrieve contacts for the account being viewed. I would like to display a message such as "No records found" if the query returns no records. I don't know if this should be added to the VF page or the controller. Code is included below;
<apex:page controller="MSContactsCon3" showheader="false">
<apex:pageBlock >
<apex:pageBlockTable value="{!contacts}" var="o">
<apex:column headervalue="Name" >
<apex:outputlink value="/{!o.id}">{!o.name}</apex:outputLink>
</apex:column>
<apex:column value="{!o.title}"/>
<apex:column value="{!o.phone}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
public class MSContactsCon3 {
String accountVar = ApexPages.currentPage().getParameters().get('id');
public ApexPages.StandardSetController setCon {
get {
if(setCon == null) {
setCon = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Id, Title, Phone, Name, Contact_type__c FROM Contact Where AccountId = :AccountVar AND contact_type__c INCLUDES ( 'Executive Contact') Order by lastname]));
}
return setCon;
}
set;
}
public List<Contact> getContacts()
{
return (List<Contact>) setCon.getRecords();
}
}
Hi MellowYellow
Please try your code which I have modified.Please feel free for further clarification on the code
All Answers
Hi MellowYellow
Please try your code which I have modified.Please feel free for further clarification on the code
Thanks!
Please set as solved