Skip to main content

Latest Post

Custom Metadata Types vs Custom Settings vs Custom Labels

  Custom Metadata Types vs Custom Settings vs Custom Labels 💬 In plain words:  Three lookalikes: Custom Metadata = configuration that DEPLOYS with your code (best for app settings). Custom Settings = org/user-specific values, changeable at runtime (hierarchy type is great for bypass switches). Custom Labels = translatable text for the UI. 📌 Example:  API endpoint URLs per environment → Custom Metadata (deploys with code, sandbox vs prod values). A 'Bypass_Automation__c' checkbox an admin flips during data load → hierarchy Custom Setting. The word 'Submit' translated to Hindi → Custom Label. 🎬 Real-Life Example: The Fee Table Trapped Inside Code  Skyline charges a different delivery fee per city. Apex needs those rates on every booking. The Old/Bad Way:  if (city == 'Delhi') fee = 50. Else if (city == 'Mumbai') fee = 65. … Every rate change is a code change, a test run, and a deployment. Why this is bad:  Business data is trappe...

Create an attractive PDF file from a Visualforce page

To create an attractive PDF file from a Visualforce page, you can use the "renderAs" attribute in the "<apex:page>" tag along with some additional styling and formatting. Here's an example:


<apex:page controller="PDFController" renderAs="pdf">

    <style>

        /* Add custom CSS styles for the PDF layout */

        body {

            font-family: Arial, sans-serif;

            font-size: 12px;

            color: #333333;

            margin: 20px;

        }

        

        h1 {

            font-size: 24px;

            color: #006699;

            margin-bottom: 20px;

        }

        

        table {

            width: 100%;

            border-collapse: collapse;

            margin-bottom: 20px;

        }

        

        th, td {

            padding: 10px;

            border: 1px solid #cccccc;

        }

        

        th {

            background-color: #f2f2f2;

            font-weight: bold;

            text-align: left;

        }

    </style>

    

    <h1>Sample PDF Report</h1>

    

    <table>

        <thead>

            <tr>

                <th>Name</th>

                <th>Email</th>

                <th>Phone</th>

            </tr>

        </thead>

        <tbody>

            <apex:repeat value="{!contacts}" var="contact">

                <tr>

                    <td>{!contact.Name}</td>

                    <td>{!contact.Email}</td>

                    <td>{!contact.Phone}</td>

                </tr>

            </apex:repeat>

        </tbody>

    </table>

</apex:page>


In this example, we have a Visualforce page that renders as a PDF using the `renderAs="pdf"` attribute in the `<apex:page>` tag. The page includes custom CSS styles defined within the `<style>` tag to control the appearance of the PDF layout.


The page content consists of a heading `<h1>` and a table displaying contact information. The contact data is fetched from the `contacts` list in the Apex controller (PDFController).


To generate the PDF file, you would need to create the corresponding Apex controller (PDFController) with the logic to retrieve the data to be displayed in the PDF.


Ensure that you format and customize the CSS styles according to your specific design preferences. You can add additional HTML elements, such as headers, footers, images, or charts, to make the PDF more visually appealing.


When the Visualforce page is accessed with the `renderAs="pdf"` attribute, it will be rendered as a PDF file, allowing users to download an attractive PDF version of the page content.


Note: Ensure that you comply with Salesforce's governor limits and consider any page size limitations when generating the PDF files.

Popular Posts

Salesforce LWC Code for Multi-Select Lookup

Introduction: In Salesforce Lightning Web Components (LWC), implementing a multi-select lookup field can enhance the user experience and provide greater flexibility for selecting multiple related records. In this blog post, we will walk through the process of creating a multi-select lookup field using LWC. We will cover the required code snippets and provide step-by-step instructions to help you implement this functionality in your Salesforce org.