Performance: 7% Flashcards
A customer has a single Visualforce page that allows each user to input up to 1500 sales forecasts and instantly view pivoted forecast calculations. Users are complaining that the page is loading slowly, and they are seeing error messages regarding heap and view state limits
What is recommended to optimize page performance (Choose 3)
A) Segregate calculation functionality from input functionality
B) Specify the list of sales forecasts as transient
C) Implement pagination and reduce records per page
D) Create formula fields to compute pivoted forecast calculations
E) Use JavaScript Remoting instead of controller actions
A, C and E
- Segregate calculation functionality from input functionality
- Implement pagination and reduce records per page
- Use JavaScript Remoting instead of controller actions
When running into Visualforce Performance issues, what are some considerations that you can look at? (list 3-7)
- Determine if Visualforce is the cause ( Not just for a single user, and not network issues)
- Avoid iframes where possible
- Use Developer Console to step through a request and determine the items that use the most system resources
- Reduce the view state size
- Use “lazy loading” to only return the data needed from SOQL queries
- Use JavaScript remoting to invoke the controller
- Use asynchronous code for any non-essential logic using Ajax
What is the maximum view state size?
Maximum view state size limit is 135KB
What options are available for reducing the view state size?
1- Use only one component per page
2- Use the transient keyword
If an SOQL query returns so many sObjects that the limit on heap size is exceeded what alternative do you have?
Use a SOQL query for loop instead
What is wrong (if any) with the following statement:
List ml = [SELECT Id,Name FROM Merchandise__c];
This is an example of a SOQL query that retrieves all merchandise items and stores them in a List variable. If the returned merchandise items are large in size and a large number of them was returned, the heap size limit might be hit.
What is wrong (if any) with the following statement: for (List ml : [SELECT Id,Name FROM Merchandise\_\_c]){ // Do something. }
Nothing. To prevent a heap size limit, querying within a for loop iterates over the returned results in batches of 200 records. This reduces the size of the m1 list variable which now holds 200 items instead of all items in the query results, and gets recreated for every batch.
Give 3 techniques for running Apex within Governor Execution Limits
1- Bulkifying DML Calls (DML calls on sObject lists versus DML calls on signle sObjects
2- More Efficient SOQL queries (Querying of child items with one SOQL query versus Inefficient querying of child items)
3- SOQL For Loops (Query within a for loop instead of query without a for loop)
What is wrong with the following piece of code:
List positionList = new List();
FOR (Position__c p : [SELECT id FROM Position__c]) {
//code block
positionList.add(p);
}
Database.update(positionList);
In this example, only one DML statement is executed outside a loof for multiple records. Although this pattern allows you to process more DML statements, it has a heap size limitation.
The better way of doing it is as follows: FOR (List positionList : [SELECT id FROM Position\_\_c]) { FOR (Position\_\_c p: positionList) { //code block } Database.update(positionList); }
This pattern allows you to process greater number of records with lesser number of DML statements without worrying about heap size limitations.
What should you look at when you exceed the total number of SOQL queries?
Move SOQL queries outside loops
What should you look at when you exceed the number of DML statements?
Insert, update, or delete records in bulk
What should you do if you exceed the total number of records retrieved by SOQL queries?
Create selective queries that filter indexed fields, such as primary keys, foreign keys, names, audit dates, or external ID fields
What are Selective SOQL Query Criteria?
When one of the query filters is on an indexed field and the query filter reduces the resulting number of rows below a system defined threshold
Which fields are indexed by default (as a consideration for a Selective SOQL query?)
Primary Keys (Id, Name and Owner fields) Foreign keys (lookup or master-detail) Audit dates (such as LastModifiedDate) Custom fields that are marked as External ID or Unique
Which fields do not allow a custom index to be created on?
Multi-select picklists Currency fields Long Text fields Some formula fields (specific TEXT(xxx) formula fields) Binary fields