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
MeghanQFSMeghanQFS 

Print Button

I want to be able to print certain fields. Can I add a button that will bring up a print preview of specific feilds and their values?
werewolfwerewolf
Well you can either use the already-built-in printable view (it's the Printable View link at the top right of every detail page) or you can create a Visualforce page that generates a PDF.  The former is much simpler of course.
Greg HGreg H
You can also use th AJAX toolkit and an sControl to accomplish your goal.
-greg
MeghanQFSMeghanQFS
Thanks Greg! Would you be able to walk me through that? Or is there info on the web somewhere I can read on how to do this?
Greg HGreg H
First you'll need to create an sControl:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
 <title>{!Account.Name}</title>
<link href="/sCSS/12.0/Theme2/common.css" type="text/css" media="handheld,print,projection,screen,tty,tv" rel="stylesheet">
<link href="/sCSS/12.0/Theme2/printableView.css" type="text/css" media="handheld,print,projection,screen,tty,tv" rel="stylesheet">
<link href="/sCSS/12.0/Theme2/elements.css" type="text/css" media="handheld,print,projection,screen,tty,tv" rel="stylesheet">
<link href="/sCSS/12.0/Theme2/dStandard.css" type="text/css" media="handheld,print,projection,screen,tty,tv" rel="stylesheet">
<!--<script src="/js/functions.js" type="text/javascript"></script>
<script src="/dJS/library.js" type="text/javascript"></script>-->
</head>

<body class="accountTab printableView">
<div class="print">
 <div class="printHeader">
  <div class="printControls">
   <ul>
    <li><a href="javascript:window.close();">Close Window</a></li>
    <li><a href="javascript:window.print();">Print This Page</a></li>
   </ul>
  </div>
  <img src="/img/sfdc_printable_logo.gif" alt="salesforce.com" width="146" height="47" title="salesforce.com">
  <div class="printHeaderBottomDiv"></div>
  <br>
 </div>
 <div class="bHeader"><h1>{!Account.Name}</h1></div>
 <div class="bPageBlock secondaryPalette" id="mainTable">
  <div class="pbHeader">
   <table  border="0" cellpadding="0" cellspacing="0">
    <tr>
     <td class="pbTitle"><img src="/s.gif" alt="" width="1" height="1" class="minWidth" title=""><h2 class="mainTitle"></h2></td>
     <td class="pbButton" id="topButtonRow">&nbsp;</td>
    </tr>
   </table>
  </div>
  <div class="pbBody">
   <div class="pbSubsection">
    <table  class="detailList" border="0" cellpadding="0" cellspacing="0">
     <tr>
      <td class="labelCol">Account Owner</td>
      <td class="dataCol col02">{!Account.OwnerFullName}</td>
      <td class="labelCol">Rating</td>
      <td class="dataCol">{!Account.Rating}</td>
     </tr>
     <tr>
      <td class="labelCol">Account Name</td>
      <td class="dataCol col02">{!Account.Name}</td>
      <td class="labelCol">Phone</td>
      <td class="dataCol">{!Account.Phone}</td>
     </tr>
     <tr>
      <td class="labelCol">Parent Account</td>
      <td class="dataCol col02">{!Account.Parent}</td>
      <td class="labelCol">Fax</td>
      <td class="dataCol">{!Account.Fax}</td>
     </tr>
    </table>
   </div>
  </div>
  <div class="pbFooter secondaryPalette"><div class="bg"></div></div>
 </div>
 <div class="bPageFooter" id="bodyFooter"><div class="footer">Copyright &copy; 2000-2008 salesforce.com, inc. All rights reserved.</div></div>
</div>

</body>
</html>

This sControl mimics the regular print page you would get within Salesforce.  It is written to pull fields from Account but you should tweak it to suit your needs. Note: due to the fact that you will be accessing this sControl from a button/link on the detail page you can use regular merge fields in your sControl (ie {!Account.Name}).
 
Second, you'll need to create a button or link for use on your detail page.  In my example you would click Setup > Customize (under App Setup) > Accounts > Buttons And Links and create a new custom detail button.  Make sure the button opens a new window and it should also call your sControl from above.
 
Third, you need add the custom button to your page layout.
-greg
sasayongsasayong
Hi Greg,

          As we know the Accounts table holds multiple field. How can we let it display with a certain rule? e.g display account.name where billing country like USA

thks
sasayongsasayong
Hi Greg,

          My question would be more of, If i'm looking up a custom object's table, and there's multiple entries in it. How can i have a page that will display entries in this object under a condition?
Greg HGreg H

Hi Sasayong,

In the example I wrote for this post I am using merge fields.  If you need to pull back different records or certain fields under certain circumstances then I suggest you use the AJAX toolkit and use a query statement to get exactly what is needed for your conditions.

If you click the "Getting Started" tab at the top of this page it will show you some of the tools that are available to you as a developer and you can find more information about the AJAX toolkit and the API.  This documentation should get you the information you need to better understand how to query and display results to the screen.

Hope this proves useful,
-greg