function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kelsey ShannonKelsey Shannon 

Code clean up advice needed

Can anyone recommend videos/articles/best practices for cleaning up old code in an org?

I inherited a messy org - 10 yrs old, 20+ triggers per object, hundreds of workflows/declarative items, and we are constantly hitting governor limits. Our code coverage is also below 75% now preventing us from deploying anything new...

My management team has granted us a 4 month new code/new project freeze to get this fixed and I don't want to waste it. 
Best Answer chosen by Kelsey Shannon
Alain CabonAlain Cabon
Hi,

1) The default reports of Salesforce at first (often the most accurate)

Setup > Quick find =  Optimizer, Lightning Experience > Check Readiness, Optimize with Features

Simple and costs nothing (very briefly): https://orgdoctor.herokuapp.com/
It is a New-Zealand tool from: https://cloudtoolkit.co/

2) Code Robot (Free): a generator of Apex unit tests : https://appexchange.salesforce.com/listingDetail?listingId=a0N3A00000ErI5CUAV
  • Pros: increase your code coverage very quickly thoughtlessly.
  • Cons: the tool itself must be installed in production.

3) PMD (Free): An extensible cross-language static code analyzer.

Performance (apex) : governor limits.  

https://pmd.github.io/pmd-5.5.7/pmd-apex/rules/index.html
  • Avoid Soql In Loops: New objects created within loops should be checked to see if they can created outside them and reused.
  • Avoid Dml Statements In Loops: Avoid DML statements inside loops to avoid hitting the DML governor limit. Instead, try to batch up the data into a list and invoke your DML once on that list of data outside the loop.
It is a Robert Sösemann's tool: https://github.com/rsoesemann?tab=repositories

PlantUML (Free) diagram generator for Salesforce orgs: https://github.com/rsoesemann/SalesforcePlantUML


4) Config Workbook (Free): ​reports of the metadata
 https://appexchange.salesforce.com/appxListingDetail?listingId=a0N30000000q4evEAA
 
 

All Answers

Alain CabonAlain Cabon
Hi,

1) The default reports of Salesforce at first (often the most accurate)

Setup > Quick find =  Optimizer, Lightning Experience > Check Readiness, Optimize with Features

Simple and costs nothing (very briefly): https://orgdoctor.herokuapp.com/
It is a New-Zealand tool from: https://cloudtoolkit.co/

2) Code Robot (Free): a generator of Apex unit tests : https://appexchange.salesforce.com/listingDetail?listingId=a0N3A00000ErI5CUAV
  • Pros: increase your code coverage very quickly thoughtlessly.
  • Cons: the tool itself must be installed in production.

3) PMD (Free): An extensible cross-language static code analyzer.

Performance (apex) : governor limits.  

https://pmd.github.io/pmd-5.5.7/pmd-apex/rules/index.html
  • Avoid Soql In Loops: New objects created within loops should be checked to see if they can created outside them and reused.
  • Avoid Dml Statements In Loops: Avoid DML statements inside loops to avoid hitting the DML governor limit. Instead, try to batch up the data into a list and invoke your DML once on that list of data outside the loop.
It is a Robert Sösemann's tool: https://github.com/rsoesemann?tab=repositories

PlantUML (Free) diagram generator for Salesforce orgs: https://github.com/rsoesemann/SalesforcePlantUML


4) Config Workbook (Free): ​reports of the metadata
 https://appexchange.salesforce.com/appxListingDetail?listingId=a0N30000000q4evEAA
 
 
This was selected as the best answer
Alain CabonAlain Cabon
Code Robot is just a free trial now in fact.

Test Class Generator for Salesforce:  not Free.
Following are the limitation, 
1. Free version supports upto 400 lines of class. Contact support@tgenbooster.com for advanced features.
2. Free version can create data upto 2 objects only. Please contact at support@tgenbosster.com for advanced features.
https://appexchange.salesforce.com/appxListingDetail?listingId=a0N3A00000EFozgUAD