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
Jefferson  EscobarJefferson Escobar 

Formula Fields or Relationships in the Queries ?

Hi All,
What is the best way in terms of performace, defining a formula field for related objects or using the clause __r  directly in the query ?

Which one is the best approach ?
e.g:
  1. Select Id, Name From Object where Custom_Formula_Field__c = 'Any'
  2. Select Id, Name From Object where Custom Related_Object__r.Custom_Field__c = 'Any'
Many thanks!
 
Best Answer chosen by Jefferson Escobar
Amit Chaudhary 8Amit Chaudhary 8
Never use fomual field in SOQL in where as per salesforce best pratice. 
https://developer.salesforce.com/blogs/engineering/2013/02/force-com-soql-best-practices-nulls-and-formula-fields.html

2nd option is good one.

Please let us know if this will help you.

Thanks
Amit Chaudhary