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
Scott.MScott.M 

Cost of Dynamic SOQL

What's the cost of using dynamic soql over standard soql queries. Is there any measurable difference between doing:

<pre>Database.query('select Id from Contact where Id=:contact_id'); </pre> 

vs

<pre>[select Id from Contact where Id=:contact_id' ]; </pre>

If there is a performance difference, does the penalty increase with complexity of queries? 

OyeCodeOyeCode
Objective is to support dynamic quries in Apex but here is what Salesforce says 

The database query method can be used wherever an inline SOQL query can be used, such as in regular assignment statements and for loops. The results are processed in much the same way as static SOQL queries are processed.

Dynamic SOQL queries have the same governor limits as static queries

So clearly, this is relative how you need it 

Read more at http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_dynamic_soql.htm