Skip to content

Org Chart Viewer ​

An interactive organization chart with search, expand/collapse and PNG export, powered by the d3-org-chart library. It loads the records of any object with a parent field itself, e.g. users and their managers, takes your own hierarchy via the records attribute, or shows a small demo dataset.

Type: Component

Available in: App Page · Home Page · Record Page

Attributes ​

NameTypeDefaultDescription
image-fieldstringAPI name of the field with an image URL shown instead of the initials, e.g. 'SmallPhotoUrl'.
name-fieldstring'Name'API name of the field shown as the name of a node.
chart-object-api-namestringAPI name of the object whose records the chart loads, e.g. 'User' or 'Contact'. Used together with parent-field-api-name; records set from outside take precedence.
parent-field-api-namestringAPI name of the field with the parent record, e.g. 'ManagerId', 'ReportsToId' or 'ParentId'.
record-idstringId of the record of the record page, filled automatically there.
recordsArray[]Flat list of records to render as a tree. Each record needs an id (or Id) and a parentId (or ManagerId), plus a name and title.
root-record-idstringId of the record the chart starts from. Without it, the chart starts from the record of the record page, if it is among the loaded records, or else shows all of them.
title-fieldstringAPI name of the field shown below the name, e.g. 'Title'.

Usage ​

Show the users of the org with their managers, photos and titles:

html
<c-org-chart-viewer
  chart-object-api-name="User"
  parent-field-api-name="ManagerId"
  title-field="Title"
  image-field="SmallPhotoUrl"
></c-org-chart-viewer>

In the Lightning App Builder, set the same values in the properties of the component, e.g. Contact with ReportsToId or Account with ParentId. On a record page of that object, the chart starts from the record of the page; Root Record Id sets another starting point.

Or pass your own hierarchy:

html
<c-org-chart-viewer records={employees} onnodeselect={handleNodeSelect}></c-org-chart-viewer>

Loading records ​

  • The records are loaded with GraphQL, so no Apex is involved and users only see records and fields they have access to. Invalid object or field names are ignored instead of being sent.
  • The chart needs one root. Records whose parent isn't loaded are roots; several roots get a shared top node named after the object, e.g. "Users". Records that can't be reached from a root, like those in a cycle, are left out.
  • At most 2000 records are loaded; if there are more, the chart says so. Set a Root Record Id to show a part of a larger hierarchy.
  • While the records load, a spinner shows; without records the chart says so, and errors are shown above it.
  • A click on a loaded record, or Enter when it has the keyboard focus, opens its record page; the shared top node, the demo data and records set from outside don't navigate.
  • Images are shown only from https:// or relative URLs. The PNG export shows the initials instead, because Salesforce doesn't allow reading images from its file domain for the export.

Events ​

NameDetailDescription
nodeselect{ record } - the record of the clicked nodeFired whenever a node in the chart is clicked, so a parent component can react to the selection. It is cancelable: preventDefault() keeps a loaded record from opening.

Custom Labels ​

The texts users see are Custom Labels, so they can be translated in Setup with the Translation Workbench. Copy them together with the component.

NameValue
ErrorAlert_ErrorError
ErrorUtils_UnknownErrorUnknown error
OrgChartViewer_CollapseAllCollapse All
OrgChartViewer_ExpandAllExpand All
OrgChartViewer_ExportPngExport PNG
OrgChartViewer_FitToScreenFit to Screen
OrgChartViewer_LibraryNotLoadedFailed to load chart library:
OrgChartViewer_LoadingLoading the org chart...
OrgChartViewer_NodeCountShowing {0} of {1} nodes
OrgChartViewer_NoRecordsNo records found.
OrgChartViewer_OnlyFirstRecordsOnly the first {0} records are shown.
OrgChartViewer_OpenRecordOpen
OrgChartViewer_RecordsNotLoadedThe records could not be loaded:
OrgChartViewer_SearchSearch
OrgChartViewer_SearchPlaceholderSearch by name...
OrgChartViewer_TitleOrg Chart Viewer
OrgChartViewer_UnknownUnknown

Component Dependencies ​

NameTypeDescription
d3orgchartStatic Resourced3 v7 + d3-flextree + d3-org-chart - Libraries for rendering interactive organization charts.
errorAlertLWCInline alert that shows error messages to the user.
errorUtilsLWCShared functions to read error messages and show error toasts.
labelUtilsLWCShared function to fill the placeholders of Custom Labels.

Released under the MIT License. · llms.txt for AI agents