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
Administrator 88Administrator 88 

render as pdf using visual force page (Render Only filled Fields in an Object) not blank fields in an object

Hi All,

I am very new to the Visual Force Page,

I got an object in which some of the fields will be filled and some of them will not. For that object i have created Button which as connected to visual force page.

When Clicked on Button, it will generate PDF file to print. 

This PDF file display/generates all fieds description and values.

But i wanted display/generate only filled fields in an object.

Is this Possible ?
 
<apex:page standardController="OPF__c" renderAs="pdf">

<html>
<head>
<style>

#sign.table { table-layout: fixed; }
#sign1.td { width: 33%; }


body
{
  font-face : arial;
  font:weight : bold;
  font-size : 13px;
}
</style>
</head>
<body>  
  <p align="center"><u><font face="Arial" weight="8"><b> Customers Purchase Order Summary Cum Shipping Instructions </b></font></u></p>
<table border="0" width="100%" cellspacing="0" cellspading="0" id="tableDate">
<tr>  
<td align="left" width="100%">Date :{!OPF__c.Date__c}</td>
</tr>

</table>  
<table border="1" width="100%" height="80%" cellspacing="0" cellspading="0" id="table1">

  <tr>
  <th width="5%" align="center"> SL.</th>
  <th width="20%" align="center"> <font face="Arial" weight="2"> Description </font>
  </th>
  <th width="75%" colspan="3">  </th>
  </tr>

  <tr>
  <td align="center"> 01 </td>
  <td align="left">GTEs Internal Reference </td>
  <td align="left" colspan="3"> {!OPF__c.Name} </td>
  </tr>
 
  <tr>
  <td align="center"> 02 </td>
  <td align="left"> Nature of Account </td>
  <td align="left" colspan="3"> {!OPF__c.Nature_of_the_Account__c}  </td>
  </tr>
 
  <tr>
  <td align="center"> 03 </td>
  <td align="left"> Primary Account Holder </td>
  <td align="left" colspan="3"> {!OPF__c.Primary_Owner_of_Acc__c}  </td>
  </tr>
  
  <tr>
  <td align="center"> 04 </td>
  <td align="left"> Technical Person </td>
  <td align="left" colspan="3"> {!OPF__c.Technical_Person__c}  </td>
  </tr>

  <tr>
  <td align="center"> 05 </td>
  <td align="left"> Technical Person Share </td>
  <td align="left" colspan="3"> {!OPF__c.Technical_Person_Share__c} % </td>
  </tr>
  
  <tr>
  <td align="center"> 06 </td>
  <td align="left"> BDE </td>
  <td align="left" colspan="3"> {!OPF__c.BDE__c}  </td>
  </tr>

  <tr>
  <td align="center"> 07 </td>
  <td align="left"> BDE Share </td>
  <td align="left" colspan="3"> {!OPF__c.BDE_Share__c} % </td>
  </tr>


........
..........
...............
..................


   </table>
   </body>
   </html>

</apex:page>

Here OPF is the object name,.
Best Answer chosen by Administrator 88
Himanshu ParasharHimanshu Parashar
Hi,

If you don't want to show label as well then you can put whole tr block inside outputpanel and conditionally render it as shown in below code.
 
<apex:outputpanel rendered="{!if(OPF__c.Nature_of_the_Account__c!=null,true,false}"
<tr>
  
  <td align="center"> 02 </td>
  <td align="left"> Nature of Account </td>
  <td align="left" colspan="3"> {!OPF__c.Nature_of_the_Account__c}  </td>
</tr>
</apex:outputpanel>


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.

 

All Answers

Himanshu ParasharHimanshu Parashar
Hi,

If you don't want to show label as well then you can put whole tr block inside outputpanel and conditionally render it as shown in below code.
 
<apex:outputpanel rendered="{!if(OPF__c.Nature_of_the_Account__c!=null,true,false}"
<tr>
  
  <td align="center"> 02 </td>
  <td align="left"> Nature of Account </td>
  <td align="left" colspan="3"> {!OPF__c.Nature_of_the_Account__c}  </td>
</tr>
</apex:outputpanel>


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.

 
This was selected as the best answer
Bhanu MaheshBhanu Mahesh
Hi,
We can hide those fields which are blank using
<tr style="display: {!IF(ISBLANK(OPF__c.Nature_of_the_Account__c), 'none', 'table-row')};">
	<td align="center"> 02 </td>
      <td align="left">Name </td>
      <td align="left" colspan="3"> {!OPF__c.Nature_of_the_Account__c} </td>
</tr>

You have hardcoded the serial number as 01, 02,03....
Because of this, even if you hide those fields, the Serials numbers will display as per the code,

So we have to make them display based on the number of fields we are displaying ie...which are not blank

For that make use of <apex:variable>

Try the below code which I have implemented for account. You can modify this as per your object fields
 
<apex:page standardController="Account" renderAs="pdf">
<apex:variable value="{!1}" var="rowNum"/>
<html>
<head>
<style>

#sign.table { table-layout: fixed; }
#sign1.td { width: 33%; }


body
{
  font-face : arial;
  font:weight : bold;
  font-size : 13px;
}
</style>
</head>
<body>  
  <p align="center"><u><font face="Arial" weight="8"><b> Customers Purchase Order Summary Cum Shipping Instructions </b></font></u></p>
<table border="0" width="100%" cellspacing="0" cellspading="0" id="tableDate">
<tr>  
<td align="left" width="100%">Date :{!Account.CreatedDate}</td>
</tr>

</table>  
<table border="1" width="100%" height="80%" cellspacing="0" cellspading="0" id="table1">

  <tr>
  <th width="5%" align="center"> SL.</th>
  <th width="20%" align="center"> <font face="Arial" weight="2"> Description </font>
  </th>
  <th width="75%" colspan="3">  </th>
  </tr>

  <tr style="display: {!IF(ISBLANK(Account.Name), 'none', 'table-row')};">
      <td align="center"> {!rowNum} </td>
      <td align="left">Name </td>
      <td align="left" colspan="3"> {!Account.Name} </td>
      <apex:variable var="rowNum" value="{!if(ISBLANK(Account.Name), rowNum, rowNum + 1)}"/>
  </tr>
 
  <tr style="display: {!IF(ISBLANK(Account.AccountNumber), 'none', 'table-row')};">
      <td align="center"> {!rowNum} </td>
      <td align="left"> Account Number </td>
      <td align="left" colspan="3"> {!Account.AccountNumber}  </td>
      <apex:variable var="rowNum" value="{!if(ISBLANK(Account.AccountNumber), rowNum, rowNum + 1)}"/>
  </tr>
 
  <tr style="display: {!IF(ISBLANK(Account.NumberOfEmployees), 'none', 'table-row')};">
      <td align="center"> {!rowNum} </td>
      <td align="left"> NumberOfEmployees </td>
      <td align="left" colspan="3"> {!Account.NumberOfEmployees}  </td>
      <apex:variable var="rowNum" value="{!if(ISBLANK(Account.NumberOfEmployees), rowNum, rowNum + 1)}"/>
  </tr>
  
  <tr style="display: {!IF(ISBLANK(Account.Account_Test__c), 'none', 'table-row')};">
      <td align="center"> {!rowNum} </td>
      <td align="left"> Account Test </td>
      <td align="left" colspan="3"> {!Account.Account_Test__c}  </td>
      <apex:variable var="rowNum" value="{!if(ISBLANK(Account.Account_Test__c), rowNum, rowNum + 1)}"/>
  </tr>

  <tr style="display: {!IF(ISBLANK(Account.Active__c), 'none', 'table-row')};">
      <td align="center"> {!rowNum} </td>
      <td align="left"> Active </td>
      <td align="left" colspan="3"> {!Account.Active__c} </td>
      <apex:variable var="rowNum" value="{!if(ISBLANK(Account.Active__c), rowNum, rowNum + 1)}"/>
  </tr>
  <tr style="display: {!IF(NOT(Account.displayerror__c), 'none', 'table-row')};">
      <td align="center"> {!rowNum} </td>
      <td align="left"> displayerror </td>
      <td align="left" colspan="3"> {!Account.displayerror__c} </td>
      <apex:variable var="rowNum" value="{!if(NOT(Account.displayerror__c), rowNum, rowNum + 1)}"/>
  </tr>

   </table>
   </body>
   </html>

</apex:page>

NOTE: Account.displayerror__c is a CheckBox field

Regards,
Bhanu Mahesh

Mark this as "SOLVED" if your issue is resolved
Administrator 88Administrator 88
Hi,

Thanks for the answers, its working great.

But have problem in one of the field, like one of the field is formula field.

Its automatically calculating values and displaying "INR 0.00".

So your code is recognizing this value and rendering in it pdf, how to avoid this issue.

Please help me with this issue.
Bhanu MaheshBhanu Mahesh
Hi,
I think the formula is  a text data type, where you are concatenating INR and another field.
Try by checking ISBLANK of that field, if that field is blank then, you can hide this field.

If that formula is calculating from more fields then use the same formula here in If condition

 <tr style="display: {!IF(your formula expression == 0 || your formula expression == null), 'none', 'table-row')};">

Regards,
Bhanu Mahesh
Administrator 88Administrator 88
Hi Mahesh,

What should i use in place of "your formula expression" ?