+ 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