Salesforce - Developer - SOQL

salesforce-developer

https://trailhead.salesforce.com/apex_database/apex_database_soql
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_sosl_intro.htm
https://www.youtube.com/watch?v=O_lZLpFjH4E - Salesforce SOQL Relationship Queries
https://www.youtube.com/watch?v=32ebJH5HK7I - Relationships in Salesforce - Lookup, Master-Detail, Many to Many and One to Many
https://developer.salesforce.com/forums/?id=906F000000090bvIAA
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships_query_using.htm
http://blog.jeffdouglas.com/2010/02/22/soql-how-i-query-with-thee-let-me-count-the-ways/
http://stackoverflow.com/questions/4027285/soql-query-with-subquery
http://womencodeheroes.com/2015/04/cooking-with-code-a-sweet-intro-to-soql-part-two/
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_locking_statements.htm
https://developer.salesforce.com/blogs/engineering/2014/07/record-locking-cheat-sheet.html
https://help.salesforce.com/articleView?id=000229525&type=1
http://salesforce.stackexchange.com/questions/22636/soql-record-locking-for-update

https://developer.salesforce.com/blogs/engineering/2013/02/force-com-soql-best-practices-nulls-and-formula-fields.html
https://developer.salesforce.com/blogs/engineering/2013/03/force-com-formula-fields-indexes-and-performance-gotchas.html
http://resources.docs.salesforce.com/rel1/doc/en-us/static/pdf/salesforce_query_search_optimization_developer_cheatsheet.pdf
https://developer.salesforce.com/blogs/engineering/2014/03/force-com-soql-best-practice-sort-optimization.html
http://salesforce.stackexchange.com/questions/55355/efficiency-when-querying-data-with-dynamic-soql-vs-formula-fields
https://www.slideshare.net/developerforce/inside-the-forcecom-query-optimizer-webinar
http://sforce.co/1zqmdsB

Basic
Miscellaneous
Optimizer
Syntax
Dynamic query
Date and time
Querying related records
i18n
Multi-select picklist
Joins

Limits
Best Practices - Querying Record in Batches By Using SOQL For Loops (Bulkify our code)
Best Practices - Avoid filtering on formula fields or contact Salesforce
Best Practices - Avoid filtering on nulls or contact Salesforce
Best Practices - Combine multiple triggers if possible
Best Practices - Enable governor limit warning email
Best Practices - Use sort optimization for large queries

// Salesforce - Developer - SOQL - Some beautiful code:

trigger contactTest on Contact (before insert, before update) {
  Set<Id> accountIds = new Set<Id>();
  for(Contact ct: Trigger.new) {
     accountIds.add(ct.AccountId);
  }

  //Do SOQL Query       
  Map<Id, Account> accounts = new Map<Id, Account>(
        [select id, name, billingState from Account where id in :accountIds]);

  for (Contact ct: Trigger.new) {
    if (accounts.get(ct.AccountId).BillingState=='CA') {
      System.debug('found a contact related to an account in california...');
      ct.email = 'test_email@testing.com';
      //Apply more logic here....
    }
  }
}

The above code show us how to use Set, Map, especially how to query 
the database and put the result into a Map in one go.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License