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
UdayWagle20UdayWagle20 

Method invocation impart on performance

Hi Everyone,

Does more number of method invocation within a class or method reduce performance in apex ?

SubratSubrat (Salesforce Developers) 
Hello Uday ,

Answer is No. Having Lengthy code in classes is concern about the storage that's it.

If we talk about performance its only related to execution time of each instruction.

Here are some best practice tips for performance.

1)Use Configuration instead of Code, if at all possible.
2)Use Maps instead of Loops, if at all possible.
3)Query before Branches, if at all possible.
4)Query only fields you need.
5)Never query inside a loop.

Try to Reuse the code that will make your class look shorter. This does not affect on performance at all but usually a best practice. 

Hope it helps !
Thank you .
Shri RajShri Raj

Yes, more method invocations in Apex can have an impact on performance, as each method call requires additional overhead for Apex to process and execute. To minimize the impact, it's important to minimize the number of method calls and optimize the code for performance by using efficient algorithms, caching data, and using the appropriate data structures. Additionally, methods that perform complex operations or have high CPU time should be refactored or optimized to reduce their processing time.