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
immaimma 

How to display just the variable != NULL


Hello everybody,
 
I want to know the way of using condition in visualforce page. I have a custom object 'Stagiaire__c' having few fields:Name,CNE,e-mail,date_de_naissance,Téléphone
 
I want to create a PDF documents whish display just the fields are not NULL
if for exemple,"CNE == null" , <p> CNE: </p> will not display in my PDF
 
Here is my code:
<apex:page standardController="Stagiaire__c" renderas="pdf" showheader="false" applyhtmltag="false" >
    <apex:pageBlock title="Fiche Stagiaire">
           <apex:pageblockTable value="{!Stagiaire__c}" var="s">
              <p>Nom & Prénom: </p>   <apex:column value="{!s.Name}"/>
              <p>CNE:</p>                  <apex:column value="{!s.CNE__c}"/>
              <p>Téléphone! </p>          <apex:column value="{!s.Téléphone__c}"/>
              <p>E-mail: </p>               <apex:column value="{!s.e-mail__c}"/>
     </apex:pageblockTable>
   </apex:pageblock>
  </apex:page>

should I create an apex Class ? if yes , how I will relate it to my page Visualforce?
 
Bhanu MaheshBhanu Mahesh
Hi imma,

Try below code 
<apex:page standardController="Stagiaire__c" renderas="pdf" showheader="false" applyhtmltag="false" >
    <apex:pageBlock title="Fiche Stagiaire">
           <apex:pageblockTable value="{!Stagiaire__c}" var="s">
              <apex:outputpanel rendered="{!ISBLANK(s.Name),false,true}">
				<p>Nom & Prénom: </p>   <apex:column value="{!s.Name}"/>
			  </apex:outputpanel>
              <apex:outputpanel rendered="{!ISBLANK(s.CNE__c),false,true}">
				<p>CNE:</p>                  <apex:column value="{!s.CNE__c}"/>
			  </apex:outputpanel>
              <apex:outputpanel rendered="{!ISBLANK(s.Téléphone__c),false,true}">
				<p>Téléphone! </p>          <apex:column value="{!s.Téléphone__c}"/>
			  </apex:outputpanel>
			  <apex:outputpanel rendered="{!ISBLANK(s.e-mail__c),false,true}">
				<p>E-mail: </p>               <apex:column value="{!s.e-mail__c}"/>
			  </apex:outputpanel>
			</apex:pageblockTable>
   </apex:pageblock>
  </apex:page>

Regards,
Bhanu Mahesh
Himanshu ParasharHimanshu Parashar
You can use following code
 
<apex:page standardController="Stagiaire__c" renderas="pdf" showheader="false" applyhtmltag="false" >
    <apex:pageBlock title="Fiche Stagiaire">
           <apex:pageblockTable value="{!Stagiaire__c}" var="s">
              <apex:outputpanel rendered="{!if(s.Name!=null,true,false)}">
               <p>Nom & Prénom: </p>   <apex:column value="{!s.Name}"/>
              </apex:outputpanel>

<apex:outputpanel rendered="{!if(s.CNE__c!=null,true,false)}">   <p>CNE: </p> <apex:column value="{!s.CNE__c}"/> </apex:outputpanel>

<apex:outputpanel rendered="{!if(s.Téléphone__c!=null,true,false)}">   <p>Téléphone!  </p> <apex:column value="{!s.Téléphone__c}"/> </apex:outputpanel>

<apex:outputpanel rendered="{!if(s.e-mail__c!=null,true,false)}">   <p>E-mail:</p> <apex:column value="{!s.e-mail__c}"/> </apex:outputpanel>

    </apex:pageblockTable>
   </apex:pageblock>
  </apex:page>

Thanks,
Himanshu
Salesforce Certified Developer | Administrator | Service Cloud Consultant

 
P.S.  If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
Dushyant SonwarDushyant Sonwar
Hi imma,
 See deepak's post
https://success.salesforce.com/apex/answers?id=90630000000CtngAAC&feedtype=SINGLE_QUESTION_DETAIL&dc=Email&criteria=BESTANSWERS&

This will help you.
immaimma
Thank you Bhanu Mahesh but I get this Error: ""Erreur de syntaxe. ',' supplémentaire"" !!!
Also for your code Mr Himanshu Parashar I get this error : ""Error: <apex:column> doit être l'enfant direct de <apex:dataTable> ou de <apex:pageBlockTable>""
Himanshu ParasharHimanshu Parashar
<apex:column value="{!s.CNE__c}" rendered="{!if(s.CNE__c!=null,true,false)}"/>
immaimma
what should I do by this line Himanshu Parashar ??
Himanshu ParasharHimanshu Parashar
<apex:page standardController="Stagiaire__c" renderas="pdf" showheader="false" applyhtmltag="false" >
    <apex:pageBlock title="Fiche Stagiaire">
           <apex:pageblockTable value="{!Stagiaire__c}" var="s">
               <p>Nom & Prénom: </p>   <apex:column rendered="{!if(s.name!=null,true,false)}"
 value="{!s.Name}"/>
             <p>CNE: </p> <apex:column value="{!s.CNE__c}" rendered="{!if(s.CNE__c!=null,true,false)}"/>

<p>Téléphone!  </p> <apex:column value="{!s.Téléphone__c}" rendered="{!if(s.CNE__c!=null,true,false)}"/> 
   <p>E-mail:</p> <apex:column value="{!s.e-mail__c}" rendered="{!if(s.e-mail__c!=null,true,false)}"/> 

    </apex:pageblockTable>
   </apex:pageblock>
  </apex:page>
immaimma
a new error : "Syntax Error" , sorry but I don't know where is the problem ,, a lot of thanks
Bhanu MaheshBhanu Mahesh
Hi Imma,

Try this
<apex:page standardController="Stagiaire__c" renderas="pdf" showheader="false" applyhtmltag="false" >
    <apex:pageBlock title="Fiche Stagiaire">
           <apex:pageblockTable value="{!Stagiaire__c}" var="s">
              <apex:outputpanel rendered="{!IF(ISBLANK(s.Name),false,true)}">
				<p>Nom & Prénom: </p>   <apex:column value="{!s.Name}"/>
			  </apex:outputpanel>
              <apex:outputpanel rendered="{!IF(ISBLANK(s.CNE__c),false,true)}">
				<p>CNE:</p>                  <apex:column value="{!s.CNE__c}"/>
			  </apex:outputpanel>
              <apex:outputpanel rendered="{!IF(ISBLANK(s.Téléphone__c),false,true)}">
				<p>Téléphone! </p>          <apex:column value="{!s.Téléphone__c}"/>
			  </apex:outputpanel>
			  <apex:outputpanel rendered="{!IF(ISBLANK(s.e-mail__c),false,true)}">
				<p>E-mail: </p>               <apex:column value="{!s.e-mail__c}"/>
			  </apex:outputpanel>
			</apex:pageblockTable>
   </apex:pageblock>
  </apex:page>

Regards,
Bhanu Mahesh
immaimma
Thank you Bhanu Mahesh for your help but i still have an error :
Error: <apex:column> doit être l'enfant direct de <apex:dataTable> ou de <apex:pageBlockTable>