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
venkyyyvenkyyy 

if there is no data in a field the page has to show error as no data found in vf page,

Hi all,

Please have a look on bellow code, and i have to show error message that if there is no data.
-----------------page-----------
<apex:page controller="controllerError">
<apex:pageBlock >
    <apex:pageBlockSection >
        <apex:pageBlockTable value="{!lst}" var="con" rendered="{ !IF(lst.size() == 0,True,False)}">
            <apex:column value="{!con.TestField__c}"/>                                  
        </apex:pageBlockTable>
    </apex:pageBlockSection>

    <apex:outputText rendered="{ !IF(lst.size()== 0,True,False)}" value="There are no contacts to display." />
    
</apex:pageBlock>
</apex:page>
----------------controller-------
public with sharing class controllerError {
    
    public list<Contact> lst{ get; set;}
    
    public controllerError(){
     lst = [select name,TestField__c from contact];
    }
    
}
-----------
suggest me what i need to add.
salesforce mesalesforce me
Hi Venkey can u create custom field on this object and u need to add the workbench code copy and paste it once this code on ur visualforce page....
KaranrajKaranraj
You can achieve this using <apex:pagemesssage> with  rendered attribute to check the list size.
Try the update visualforce page code
<apex:page controller="controllerError">
<apex:pageMessage summary="No Contact" severity="error" rendered="{!lst.size == 0}" strength="1"  > </apex:pageMessage>
<apex:pageBlock rendered="{!lst.size != 0}">
    <apex:pageBlockSection >
        <apex:pageBlockTable value="{!lst}" var="con" >
            <apex:column value="{!con.TestField__c}"/>                                  
        </apex:pageBlockTable>
    </apex:pageBlockSection>
</apex:pageBlock>
</apex:page>

Thanks,
Karanraj (http://www.karanrajs.com)

 
venkyyyvenkyyy
Hi Karanraj,
I did the same what you said and doing paste bellow, it is not working as per my expectaion, can u check it once and do correct me where i did wrong,
-----------vf----
<apex:page controller="controllerError">
<apex:pageMessage summary="No Contacts" severity="error" rendered="{!IF(lst.size == 0,True,False)}" strength="1"  > </apex:pageMessage>
<apex:pageBlock rendered="{!IF(lst.size != 0,True,False)}">
    <apex:pageBlockSection >
        <apex:pageBlockTable value="{!lst}" var="con" >
            <apex:column value="{!con.TestField__c}"/>                                  
        </apex:pageBlockTable>
    </apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
--------controller---
public with sharing class controllerError {
    
    public list<Contact> lst{ get; set;}
    
    public controllerError(){
     lst = [select name,TestField__c from contact];
    }
    
}
----

Thanks, 
Venky.