Skip to main content

Latest Post

Record Types & Page Layout Strategy

  Record Types & Page Layout Strategy 💬 In plain words:   Record Types let one object act like different forms for different teams. Different picklist values, page layouts, and processes — same Account object. Use them for truly different business processes. Not for cosmetic layout changes. 📌 Example:   One Account object, two businesses: 'Retail Customer' record type shows B2C picklist values and layout. 'Enterprise Client' shows contract fields and a different sales process. Same table, two costumes. 🧠 One object, many costumes:   A Record Type is a costume on the same object — different picklists and layouts, same table underneath. Concept Record Types split one object into business variants. •   Each type can carry its own subset of picklist values, its own business process — Lead, Case and Opportunity stages — and its own page layout per profile. •   Lightning has changed the calculus. Dynamic Forms and conditional comp...

Create an attractive tree view of records using Apex and Visualforce in salesforce

 To create an attractive tree view of records using Apex and Visualforce, you can follow these steps:


1. Create a Visualforce page:

   Start by creating a Visualforce page where you will display the tree view of records.


   <apex:page controller="TreeViewController">

       <apex:form>

           <apex:pageBlock>

               <apex:pageBlockSection>

                   <apex:outputPanel id="treePanel">

                       <ul id="tree">

                           <apex:repeat value="{!treeNodes}" var="node">

                               <li>

                                   <apex:outputText value="{!node.name}" styleClass="node-label" />

                                   <ul>

                                       <apex:repeat value="{!node.children}" var="child">

                                           <li>

                                               <apex:outputText value="{!child.name}" styleClass="node-label" />

                                               <!-- Repeat the above pattern for nested children if needed -->

                                           </li>

                                       </apex:repeat>

                                   </ul>

                               </li>

                           </apex:repeat>

                       </ul>

                   </apex:outputPanel>

               </apex:pageBlockSection>

           </apex:pageBlock>

       </apex:form>

   </apex:page>


2. Create a controller class:

   Create a controller class that will handle the logic for the Visualforce page. This class will generate the tree structure of records.



   public class TreeViewController {

       public List<TreeNode> treeNodes { get; set; }


       public TreeViewController() {

           treeNodes = new List<TreeNode>();


           // Generate your tree structure here

           // Example:

           TreeNode rootNode = new TreeNode('Root');

           TreeNode childNode1 = new TreeNode('Child 1');

           TreeNode childNode2 = new TreeNode('Child 2');

           TreeNode grandchildNode1 = new TreeNode('Grandchild 1');

           TreeNode grandchildNode2 = new TreeNode('Grandchild 2');


           childNode1.children.add(grandchildNode1);

           childNode1.children.add(grandchildNode2);

           rootNode.children.add(childNode1);

           rootNode.children.add(childNode2);


           treeNodes.add(rootNode);

       }


       public class TreeNode {

           public String name { get; set; }

           public List<TreeNode> children { get; set; }


           public TreeNode(String name) {

               this.name = name;

               children = new List<TreeNode>();

           }

       }

   }


   In this example, the controller class generates a sample tree structure using the 'TreeNode' class. Each 'TreeNode' object represents a node in the tree and contains a name and a list of child nodes.


3. Save the Visualforce page and the controller class:

   Save the Visualforce page with a suitable name, such as "TreeViewPage", and the controller class with a suitable name, such as "TreeViewController".


4. Add CSS styles:

   To make the tree view visually attractive, you can add CSS styles to the Visualforce page or in a separate CSS file. Here's an example of adding styles to the Visualforce page:


   <style>

       ul#tree {

           list-style-type: none;

           padding: 0;

       }


       ul#tree li {

           margin-bottom: 10px;

       }


       .node-label {

           display: inline-block;

           margin-left: 10px;

           cursor: pointer;

       }

   </style>


   Customize the styles as per your design preferences.


5. Access the Visualforce page:

   You can access the Visualforce page by appending its name to the Salesforce organization URL/

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.