Complexity scoring on metadata

How does Elements calculate complexity of automations

Ksawery Lisinski avatar
Written by Ksawery Lisinski
Updated over a week ago

Elements.cloud automatically calculates complexity scores and score levels for some metadata types. This helps in reporting aggregate complexity of automations and finding specific automations that need optimization.

Prerequisites

The complexity calculation process happens automatically for any Org that is connected and synced with Elements.cloud

Apex complexity scoring

Apex class complexity scoring is done using PMD package and includes 2 parameters:

  • Cyclomatic complexity score: Cyclomatic complexity assesses the complexity by counting the number of decision points in a method, plus one for the method entry. Decision points are places where the control flow jumps to another place in the program. As such, they include all control flow statements, such as ‘if’, ‘while’, ‘for’, and ‘case’.

  • Cognitive complexity score: Cognitive complexity is a measure of how difficult it is for humans to read and understand code. Code that contains a break in the control flow is more complex, whereas the use of language shorthands doesn’t increase the level of complexity. Nested control flows can make a method more difficult to understand, with each additional nesting of the control flow leading to an increase in cognitive complexity.

Both complexity scores are then added together and compared to hard-coded boundaries to determine the score classification:

  • boundary 1: 10

  • boundary 2: 25

  • boundary 3: 50

Range scores:

  • below 10: Low

  • score 11-25: Medium

  • score 26-50: High

  • score above 50: Extremely high

Flow complexity scoring

Flow complexity scoring is done by Elements.cloud and is meant to mimic the cognitive and cyclomatic complexity scores used for apex. In other words, a highly complex flow is one that is either extremely big or has a lot of branching logic.

For every element in a flow that we detect we assign a score. The flow elements have following scores assigned to them:

  • Loop: 5

  • Decision: 3

  • Subflow: 3

  • Screen: 3

  • Any DML elements: 2

  • Formula elements: 2

  • Assignment: 1

  • Callout: 1

  • Any other element: 1

So a flow that is composed of 5 elements: Decision, Assignment, Screen and 2 DML elements (e.g. create record and update record) would get a total complexity score of 11.

Flow complexity score is then compared to hard-coded boundaries to determine the score classification:

  • boundary 1: 10

  • boundary 2: 25

  • boundary 3: 100

Range scores:

  • below 10: Low

  • score 11-25: Medium

  • score 26-100: High

  • score above 100: Extremely high

Did this answer your question?