Challenge Overview
Our client is transforming its CRM, Self Serve, and Console services in Salesforce across business units, resulting in more than 1,600 Apex Classes, 100 triggers and voluminous LWC codes introduced by developers. This presents challenge in the following areas:
-
Accurately identifying potential impacts when introducing change
-
Potentially introducing duplicate logic; requiring build effort that should not be needed in the first place
-
Possibility of breaking the flow performing defect fixes
To simplify this we are going to build a Salesforce Apex Code and Metadata Analyser CLI that will extend the SFDX CLI to parse Salesforce artefacts offline and generate a symbol tree/dependency tree script (ClassDiagram script) that can be used to generate the UML diagram using Mermaid-JS. Ref this live editor for a quick demo.
In this challenge it is expected that the CLI will be built as a SFDX plugin. The open-source project https://github.com/forcedotcom/dependencies-cli should be used as the boilerplate and adaptation to be made in the following areas:
-
Extend the plugin to enable Bulk API 2.0 to pull more than 2,000 records of dependency data.
-
The solution must leverage all the existing authentication mechanism supported by the sfdx-cli
-
force:auth:device:login
-
+ other default mechanisms
-
The generation of the symbol tree/dependency tree script (ClassDiagram script) in CSV format is in scope.
Technology Stack
-
JavaScript
-
Salesforce MetadataComponentDependency API (Bulk API 2.0, API49.0)
-
SOQL (Similar to SQL)
General requirements
Code Formatting
-
Make sure code is well documented, all classes, methods, variables, parameters, return values must be documented in every single code file, and appropriate inline comments should be provided too where the code is not straightforward to understand.
-
Please use clean INDENTATION for all the code so future developers can follow the code.
-
Use appropriate linter to validate your code.
JAVASCRIPT SPECIFIC
-
Code written in JavaScript should pass the EsLint Validation.
LAYOUT
We don’t have a storyboard/design for the extension. You can use your best judgement for the layout.
PLATFORM
The CLI should run from the Terminal/Command prompt of Windows, Linux & Mac
REFERENCES:
-
Salesforce API overview
Business Requirements
Resources
Automation-components Salesforce repo should be used to test the ClassDiagram generation using the CLI command you will be creating in this challenge.
Running the command: sfdx force:data:soql:query -q "SELECT MetadataComponentName, MetadataComponentType, RefMetadataComponentName FROM MetadataComponentDependency WHERE RefMetadataComponentType = 'ApexClass'" --resultformat json --apiversion 49.0 -t
Return the following result , here RefMetadataComponentType = 'ApexClass'". This is for reference that can be used when creating the required CLI command.
ClassDiagram Script
The following command should be created:
sfdx dependencies:component:report:whereused -component [ApexClass,ApexClass:MyClass,LWC,LWC:MyLWC]
sfdx dependencies:component:report:unusedcomponents -r [class|method|field]
Command-line switches
-component (optional): When specified, it contains a list of component type, componentType:componentName to be included in the diagram. When ALL is specified, the diagram will show all supported node types, i.e. ApexClass (of all prototypes) and LWC.
Sample output
This will be a text-base output, supporting the following format (controlled by CLI switch):
-
Comma separated values (CSV)
The report should cover the following topics:
-
Where-use of a given Apex Class and Method using: sfdx dependencies:component:report:whereused -component [ApexClass,ApexClass: MyClass,LWC,LWC:MyLWC, Trigger, Trigger:TriggerABC]
-
Example Output
Class Name | Method Name | Used By Component | Component Type |
Class001 | doABC | ClassABC | ApexClass |
Class002 | doDEF | ClassXYZ | ApexClass |
LigthingElement001 | ??? | CompomentABC | LWC |
-
Un-used class/method/field exception report using: sfdx dependencies:component:report:unusedcomponents -r [class|method|field]
-
Example Output
Component Name | Component Type | Parent Name |
ClassXYZ | ApexClass | |
FieldName__c | Field | Account |
MethodABC | Method | ClassDEF |
Final Submission Guidelines
Submit a zip container containing:
- Source code
- Readme/Instructions to run the code.
- A video/snapshot demonstration of how your code works.