ABSYZ ABSYZ

  • Home

    Home

  • About us

    Who We Are

  • Our Expertise

    What we Do

  • Our Approach

    How We Do It

  • Products

    What We Made

  • Industries

    Who We Do It For

  • Clients

    Whom We Did It For.

  • Article & Blogs

    What Experts Think

  • Careers

    Join The Team

  • Get In Touch

    Let’s Get Started

ABSYZ

SObject Tree Structure

Home / Article & Blogs / Apex / SObject Tree Structure
By Team ABSYZ inApex, Lightning, Salesforce

In this article, we are implementing a Tree Structure which displays all the parent and its respective child and grandchild records. When clicked on certain parent record, its respective child records are shown and when we click on child records they respective grandchild records are displayed. This goes on. The current implementation is generic which works on all objects. Select an object initially, then the records of the object are displayed in the Tree Structure.

Create a custom metadata object

Custom Metadata:

Used to display child records based on metadata records.

Custom Metadata API Name
Custom Fields API Name
Description
Object_With_Child_

Relationship_Name__mdt

Child_Relationship_Name__c
It should have Child Relationship Name.
Parent_Object_API_Name__c
It should have parent object API Name
Custom Metadata

Ex:

Parent Object
Child Relationship Name
AccountContacts

Opportunities

Create a metadata with which objects you want to display to get the records from and their child objects. Those objects will be displayed in the picklist.

Screen Shot 2017-03-02 at 12.48.53 PM.png

Select the object which you want to retrieve the records.
Screen Shot 2017-03-02 at 12.49.03 PM.png

In the below code i am trying to get the SObject API Names by using schema and checking with Metadata, if API Name of the SObject present in Metadata it will display in picklist field.Screen Shot 2017-03-08 at 11.40.34 PM.pngWhen you select a particular object and click on Get Records button you will get the particular selected object record.

If you have a self-relationship it will display only records which are not self-related records.

Ex: Let say we have Account1, Account2, Account3, Account4 records in account object.

For Account3 and Account4, Account1 is the parent.

So when you click on Get Records button it will display Account1 and Account2 but not Account3 and Account4 because Account3 and Account4 are the child records.

Screen Shot 2017-03-06 at 11.24.26 PM.png

If you want to get the child records which are related to particular parent record you need to click on the arrow button. It will display all object records which are defined in metadata only.

Screen Shot 2017-03-06 at 11.25.01 PM.png

If your parent record doesn’t have any child records it will a message.

Screen Shot 2017-03-06 at 11.25.58 PM.png

In the below code i am checking if the relationship name is present in Custom Metadata or not.Screen Shot 2017-03-08 at 11.47.05 PM.pngWe don’t know how many levels it goes so I am creating a component dynamically to display records in page.Screen Shot 2017-03-08 at 11.48.54 PM.png

Limitations:

As per the salesforce governor limits, we can able to retrieve 20 child relationships object records from SOQL.

For some the objects, it won’t be supported for Notes&Attachments

Note:

In custom metadata, you should have only 20 child relationships per parent object.

References:

View code in Github

Tree Structure
87
Like this post
127 Posts
Team ABSYZ

Search Posts

Archives

Categories

Recent posts

BioAsia 2023 in Hyderabad: An Annual International Event

BioAsia 2023 in Hyderabad: An Annual International Event

The Role Of Marketing in Small & Medium Enterprises

The Role Of Marketing in Small & Medium Enterprises

Salesforce For Retail: How Salesforce CRM Can Help Retailers

Salesforce For Retail: How Salesforce CRM Can Help Retailers

What is ChatGPT & How Does It Work?

What is ChatGPT & How Does It Work?

What Is Graphic Design? (Executive Summary 2023)

What Is Graphic Design? (Executive Summary 2023)

  • Previous PostCreating a custom search Engine in Salesforce
  • Next PostSalesforce Summer '17 Release : Lightning for Gmail -Part I

Related Posts

Salesforce For Retail: How Salesforce CRM Can Help Retailers
Salesforce

Salesforce For Retail: How Salesforce CRM Can Help Retailers

Introduction To Copado Devops Tool
Salesforce

Introduction To Copado Devops Tool

What is Salesforce Code Builder?
Salesforce

What is Salesforce Code Builder?

Automation in Healthcare And Its Benefits
Health Cloud Salesforce

Automation in Healthcare And Its Benefits

1 Comment

  1. pravin s
    Reply
    25 March 2021

    will it work for child accounts?

    Reply

Leave a Reply (Cancel reply)

Your email address will not be published. Required fields are marked *

*
*

ABSYZ Logo

INDIA | USA | UAE

  • About us
  • Article & Blogs
  • Careers
  • Get In Touch
  • Our Expertise
  • Our Approach
  • Products
  • Industries
  • Clients
  • White Papers

Copyright ©2022 Absyz Inc. All Rights Reserved.

youngsoft
Copy
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “ACCEPT ALL”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent. Privacy Policy
Cookie SettingsREJECT ALLACCEPT ALL
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled

Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.

CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.

Functional

Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.

Performance

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

Analytics

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.

Advertisement

Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.

Others

Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.

SAVE & ACCEPT