You would like to go through this useful cheat sheet for “Query and Search” optimization, few of this is discussed in this post as FAQ.
171 : How Standard Fields and Custom Fields related information is saved inside Salesforce Database? Is every Standard and Custom Object is created as a different Database table?
Salesforce is using Multi-tenant architecture, means many organizations (Tenants) are using same infrastructure. Salesforce Database saves Metadata Information in hundreds of table. Run time engine then generates organization specific query to get information about their organizations and Data from common table as shown in below diagram. Below Database tables are partitioned by Organization ID and generates virtual table specific to Org.
172 : As a Developer, how can you optimize SQL query to fetch data from Salesforce Database?
As Salesforce doesn’t save data in traditional way. Data of all tenants are in common table, so traditional Query optimization query and technique will not work in this case, so there is no such tool available to optimize final generated SQL. We only have option to create SOQL which is optimized by custom inbuilt Force.com Query Optimizer.
In Summer14, Salesforce released Query Plan Tool to analyze how query is performing. With help of this tool, we can get an idea how we can change our query to perform better.
173 : When records are created in Salesforce, How it is queued for Indexing?
If newly created records are equal to or less than 9000, then it will be indexed in 1 to 3 minutes. However if records are more than 9000, then servers perform bulk indexing at a lower priority, so processing might take longer.
174 : Explain functionality of Force.com Query Optimizer.
The Force.com query optimizer:
- Determines the best index from which to drive the query, if possible, based on filters in the query
- Determines the best table to drive the query from if no good index is available
- Determines how to order the remaining tables to minimize cost
- Injects custom foreign key value tables as needed to create efficient join paths
- Influences the execution plan for the remaining joins, including sharing joins, to minimize database input/output (I/O)
- Updates statistics
175 : Explain term “Data Skew” in Salesforce.
Scenario in which parent record has more than 10,000 of records or if any user owns more than 10,000 records is known as “Data Skew”. Salesforce does not recommend having more than 10,000 records own by any user or more than 10,000 Child for any parent.
176 : Explain Skinny table.
Salesforce creates skinny tables to contain frequently used fields and to avoid joins, and it keeps the skinny tables in sync with their source tables when the source tables are modified. To enable skinny tables, contact Salesforce.com Customer Support.
For each object table, Salesforce maintains other, separate tables at the database level for standard and custom fields. This separation ordinarily necessitates a join when a query contains both kinds of fields. A skinny table contains both kinds of fields and does not include soft-deleted records.
This table shows an Account view, a corresponding database table, and a skinny table that would speed up Account queries.
177 : What are the considerations for Skinny Table?
- Skinny tables can contain a maximum of 100 columns.
- Skinny tables cannot contain fields from other objects.
- Skinny tables are not copied to sandbox organizations. To have production skinny tables activated in a sandbox organization, contact salesforce.com Customer Support.
178 : Which fields are automatically Indexed in Salesforce?
- Systemmodstamp (LastModifiedDate)
- Email (for contacts and leads)
- Foreign key relationships (lookups and master-detail)
- The unique Salesforce record ID, which is the primary key for each object
179 : Which fields cannot be added as a custom Index?
- multi-select picklists
- text area (long)
- text area (rich)
- non-deterministic formula fields (Like any formula field using function NOW() or Today() )
- encrypted text fields
180 : When Salesforce will use Standard Indexed fields?
Salesforce maintains statistics table which stores information about records present in Organization. If records going to be searched is less than or equal to 30% of total records or up to 1 million records then only it makes sense to use standard Indexed fields to narrow result else total records going to be returned is more than 30% already so Salesforce will not use any indexing.
181 : When Salesforce will use Custom Indexed fields?
Salesforce maintains statistics table which stores information about records present in Organization. If records going to be searched is less than or equal to 10% of total records or up to 333,333 records then only it makes sense to use standard Indexed fields to narrow result else total records going to be returned is more than 10% already so Salesforce will not use any indexing.
182 : What are examples of Non-deterministic Force.com formula fields?
- Reference other entities (i.e., fields accessible through lookup fields
- Include other formula fields that span over other entities
- Use dynamic date and time functions (e.g., TODAY and NOW)
- If formula field includes
- Owner, autonumber, divisions, or audit fields (except for CreatedDate and CreatedByID fields
- References to fields that Force.com cannot index
- Multi-select picklists
- Currency fields in a multicurrency organization
- Long text area fields
- Binary fields (blob, file, or encrypted text)
There are few standard fields also which are considered as non-deterministic which can be found in salesforce documentations.
183 : Explain Two-Column Custom Indexes.
Two-column custom indexes are a specialized feature of the Salesforce platform. They are useful for list views and other situations in which you want to use one field to select the records to display and a second field to sort those records.
Two-column indexes are subject to the same restrictions as single-column indexes, with one exception. Two-column indexes can have nulls in the second column by default, whereas single-column indexes cannot, unless salesforce.com Customer Support has explicitly enabled the option to include nulls.
184 : What is Defer Sharing Calculation ?
This feature allows users to defer the processing of sharing rules until after new users, rules, and other content have been loaded. This is very useful and handy feature to speed up data loading by avoiding calculation of Sharing rules.
185 : How can we load millions of records in Salesforce within an hour ?
Ans : We can use Bulk Data loading and turn ON Parallel loading. Check this Webinar recording for loading 20 millions record in one hour.
186 : In case of parallel data loading, how to avoid record locked error ?
Ans : Record locked error can be avoided by two ways
- Change schema of Object : Check every Lookup field and make sure that in Lookup Option you have not selected “Don’t allow deletion of the lookup record that’s part of lookup relationship”. Because of this selection, even during insert operation system hold lock against record and other batches accessing same record fails.
- Order Insert operations in CSV File : In this option, Sort column containing parent record Id for Lookup fields. So all records of same parent will be loaded in same batch and parent record locked problem across batch will be resolved. Check this Webinar recording for loading 20 millions record in one hour.
- Other reasons of lock may be Rollup Summary, Workflow, Trigger etc.