+ 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 Lynda.com about Refactoring code from one of the best in business: SIMON ALLARDICE!

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.