Performance: 7% Flashcards Preview

SFDC Platform Dev II > Performance: 7% > Flashcards

Flashcards in Performance: 7% Deck (19)
Loading flashcards...
1
Q

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

A, C and E

  1. Segregate calculation functionality from input functionality
  2. Implement pagination and reduce records per page
  3. Use JavaScript Remoting instead of controller actions
2
Q

When running into Visualforce Performance issues, what are some considerations that you can look at? (list 3-7)

A
  1. Determine if Visualforce is the cause ( Not just for a single user, and not network issues)
  2. Avoid iframes where possible
  3. Use Developer Console to step through a request and determine the items that use the most system resources
  4. Reduce the view state size
  5. Use “lazy loading” to only return the data needed from SOQL queries
  6. Use JavaScript remoting to invoke the controller
  7. Use asynchronous code for any non-essential logic using Ajax
3
Q

What is the maximum view state size?

A

Maximum view state size limit is 135KB

4
Q

What options are available for reducing the view state size?

A

1- Use only one component per page

2- Use the transient keyword

5
Q

If an SOQL query returns so many sObjects that the limit on heap size is exceeded what alternative do you have?

A

Use a SOQL query for loop instead

6
Q

What is wrong (if any) with the following statement:

List ml = [SELECT Id,Name FROM Merchandise__c];

A

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.

7
Q
What is wrong (if any) with the following statement:
for (List ml : [SELECT Id,Name FROM Merchandise\_\_c]){
    // Do something.
}
A

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.

8
Q

Give 3 techniques for running Apex within Governor Execution Limits

A

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)

9
Q

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);

A

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.

10
Q

What should you look at when you exceed the total number of SOQL queries?

A

Move SOQL queries outside loops

11
Q

What should you look at when you exceed the number of DML statements?

A

Insert, update, or delete records in bulk

12
Q

What should you do if you exceed the total number of records retrieved by SOQL queries?

A

Create selective queries that filter indexed fields, such as primary keys, foreign keys, names, audit dates, or external ID fields

13
Q

What are Selective SOQL Query Criteria?

A

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

14
Q

Which fields are indexed by default (as a consideration for a Selective SOQL query?)

A
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
15
Q

Which fields do not allow a custom index to be created on?

A
Multi-select picklists
Currency fields
Long Text fields
Some formula fields (specific TEXT(xxx) formula fields)
Binary fields
16
Q

Is the following a selective query or not?

SELECT Id FROM Account WHERE Id IN ( list of account IDs )

A

Yes, the where clause is on an indexed field (Id)

17
Q

Is the following a selective query or not?

SELECT Id FROM Account WHERE Name != ‘’

A

Not a selective query: Since Account is a large object even though Name is indexed (primary key), this filter returns most of the records, making the query non-selective.

18
Q

Is the following a selective query or not?

SELECT Id FROM Account WHERE Name != ‘’ AND CustomField__c = ‘ValueA’

A

Depends
The first filter isn’t selective. So let’s focus on the second one. If the count of records returned by SELECT COUNT() FROM Account WHERE CustomField__c = ‘ValueA’ is lower than the selectivity threshold, and CustomField__c is indexed, the query is selective.

19
Q

Which value should you exclude from in SOSL and SOQL statements to improve performance?

A

Avoid searching records that contain null values. Filter our null values first to improve performance.(For example, if you are creating a search string dynamically using input parameters, then in the same query search for the field__c= :inputValue AND field__c != null