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
Jim BoudreauxJim Boudreaux 

Best Practice Question

Ok, as I see it as a Force.com developer we have two choices. Either we could put all our visualforce code in one page and cover everything we need in one controller or we can break up our visualforce code in multiple pages and components, including the pages and components and break up our apex code into multiple classes with references to each other.

 

My question is, is there any advantage to the second option beyond code reusability, in particular is there any advantage when it comes to governor limits or processing time? In other words if I had a visualforce page that makes 100 SOQL statements and used 200,000 script statements, would I gain any kind of performance advantage by breaking up my code into custom components, referenced apex classes, and included visualforce pages?

 

Thanks for any advise.  

InnovationInnovation

There's probably 1,000 different angles to cover here, but in general I would say it depends on the scope of the development.  Doing a minor CRM extension?  Probably doesn't make sense to burn cycles on an elegant service oriented or component architecture; just crank out some code, get it in front of the users, and refactor based on the feedback you get from UAT.  Building a large commercial app?  Then yeah, design it for performance, reusability, context abstraction, etc. Running unnecessary queries is going to add performance cost to your code, as is loading page content or JS libraries that you're not going to end up using, etc.  On the other hand, if you can create enough abstraction and build a loosely coupled component framework, you give yourself a great deal of leverage in rapidly implementing new functionality as you don't have to reinvent the wheel for basic interfaces and actions.  One basic principle that I try to follow as much as possible is read once, use many - i.e. rather than trying to perform specific functions by executing multiple queries (expensive), abstract the query to the point where it will satisfy all of the required data read operations for the given function and perform manipulation functions (i.e. aggregation, filtering, sorting) using in-memory iteration methods...now that the 1,000-item governor limit has been lifted from sets / maps / lists, this is much more straightforward than it used to be.

 

Jim BoudreauxJim Boudreaux

Thanks for your response, but what I really want to know is do I save any processing power by breaking my code up into different parts. If I have one umbrella app that makes uses multiple classes that in turn make multiple queries, do all of these count toward one resource pool or does each class operate under different restrictions.

 

In  other words if I have a class that makes 10 queries and I call it 11 times will I get an error?

If so is there a general work around, or is this resource pool just something I have to keep in mind and consider a drawback of multi-tenancy architecture?