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
pavan kumar 1156pavan kumar 1156 

Hai can any one explain please?

what is Refactoring in apex ?how can we use it? is there any scenarios to use it?
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:
There is a wonderful course on about Refactoring code from one of the best in business: SIMON ALLARDICE!


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.