ABSYZ ABSYZ

  • Home

    Welcome to ABSYZ

  • 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

SObject Tree Structure

By pradeepkumar batta 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
Account Contacts

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
38
Like this post
2 Posts
pradeepkumar batta

Search Posts

Archives

Categories

Recent posts

Top 5 Factors to evaluate before choosing a Salesforce Integrator

Top 5 Factors to evaluate before choosing a Salesforce Integrator

Significance of UI/UX Design

Significance of UI/UX Design

Cyber-security in an uncertain world

Cyber-security in an uncertain world

The world of AR and VR

The world of AR and VR

The in-and-out of ML

The in-and-out of ML

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

Related Posts

Cyber-security in an uncertain world
Apex

Cyber-security in an uncertain world

REST API call from Einstein Analytics Dashboard
Apex REST Salesforce Salesforce Einstein Wave Analytics

REST API call from Einstein Analytics Dashboard

Create/Update Salesforce Picklist definitions using metadata API
Integration Metadata API Salesforce

Create/Update Salesforce Picklist definitions using metadata API

Leave a Reply (Cancel reply)

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

*
*

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

ABSYZ Software Consulting Pvt. Ltd.
USA: 49197 Wixom Tech Dr, Wixom, MI 48393, USA
M: +1.415.364.8055

India: 6th Floor, SS Techpark, PSR Prime, DLF Cyber City, Gachibowli, Hyderabad, Telangana – 500032
M: +91 79979 66174

Copyright ©2020 Absyz Inc. All Rights Reserved.

youngsoft
Copy