Code refactoring is a process of restructuring existing code without changing the behavior of the code. It is being done to follow the best practices in coding. We do have certain standards which we are supposed to follow for better performance and code optimization.
Few best practices are: --> Use Map to organise data. --> Streamline your query. If you are not using any field then remove it from the query. --> Use limit clause to you query. --> Always check for null. --> Use list return type to query --> to avoid no rows assignment to sObject. --> Donot use more than 2 nested loops... Complexity and CPU time increases. --> Understand bulk processing from below link. --> Donot keep unused variabled. Always release space of variables once its usage is done. It will help you to manage heap size.
Below are some links to understad salesforce apex best practices: https://developer.salesforce.com/page/Apex_Code_Best_Practices
Few best practices are:
--> Use Map to organise data.
--> Streamline your query. If you are not using any field then remove it from the query.
--> Use limit clause to you query.
--> Always check for null.
--> Use list return type to query --> to avoid no rows assignment to sObject.
--> Donot use more than 2 nested loops... Complexity and CPU time increases.
--> Understand bulk processing from below link.
--> Donot keep unused variabled. Always release space of variables once its usage is done. It will help you to manage heap size.
Below are some links to understad salesforce apex best practices:
https://developer.salesforce.com/page/Apex_Code_Best_Practices
Link: https://www.lynda.com/Developer-Programming-Foundations-tutorials/Foundations-Programming-Refactoring-Code/122457-2.html
It's shown in an Object Oriented Programming language and so we (an APEX DEVELOPERS!) can benefit from it.
There are lots of key takeaways fromt he course. Highly recommended!
Hope it helps.