Skip to content

Reduce complexity in Salesforce workers

Problem

A Code Climate report (attached here) has identified multiple problems with the Salesforce workers like Salesforce::CreateAccountWorker. These workers can be quite complex with a long list of parameters that can be passed in.

Click to expand

Screenshot_2024-08-23_at_3.59.02_PM

Screenshot_2024-08-23_at_3.59.28_PM

Screenshot_2024-08-23_at_4.05.30_PM

Screenshot_2024-08-23_at_4.10.27_PM

  • Salesforce::CreateAccountWorker
    • Method perform has 8 arguments (exceeds 4 allowed).
    • Method perform has a Cognitive Complexity of 12 (exceeds 5 allowed).
  • Salesforce::CreateOpportunityWorker
    • Method integration_perform has 6 arguments (exceeds 4 allowed).
  • Salesforce::CreateQuoteForReconciliationWorker
    • Method integration_perform has a Cognitive Complexity of 9 (exceeds 5 allowed).
    • Method integration_perform has 43 lines of code (exceeds 25 allowed).
  • Salesforce::CreateQuoteRatePlanChargeService
    • Method initialize has 33 lines of code (exceeds 25 allowed).
    • Method attributes has 32 lines of code (exceeds 25 allowed).
  • Salesforce::CreateQuoteService
    • Method attributes has 28 lines of code (exceeds 25 allowed).

There is a similar thread of complexity throughout these workers.

Proposal

Let's consider some solutions that can be applied across these classes to reduce complexity.