top of page

Dynamic SOQL ( queryBinds ) || Salesforce

Dynamic SOQL refers to the creation of a SOQL string at run time with Apex code. Dynamic SOQL enables you to create more flexible applications. For example, you can create a search based on input from an end user or update records with varying field names.


In general we write advance / dynamic query something like this

sObject objectRecord = Database.query('SELECT Id , Name FROM Account LIMIT 1');

if it is for collection then something like this

List<sObject> objectRecord = Database.query('SELECT Id , Name FROM Account');

But in Spring'23 we got new update from salesforce i.e query Binds, with the help of query binds we can pass the dynamic query variable reference without any query scope limits


With Database.query, All variable references need to maintain within the Apex Class Query scope. By using Database.queryBind no need to worry about scope of query and variables all this handled by BindsMap.


Map<String, Object> acctBinds = new Map<String, Object>{'acctName' => 'Acme Corporation'};

List<Account> accts = Database.queryWithBinds('SELECT Id FROM Account WHERE Name = :acctName',acctBinds,AccessLevel.USER_MODE);
	


12 Comments


This is a very well-written and engaging post. The tone feels natural and reader-friendly. It made the entire reading experience enjoyable. Great effort!

Like

I really appreciate the effort behind this post. It’s well-structured and easy to understand. The content feels genuine and helpful. Looking forward to more like this!

Like

rPeptide
rPeptide
Mar 30

This blog really helped me understand the topic better. The explanations are simple yet effective. I appreciate the effort you’ve put into making it reader-friendly. Great job!

Like

This blog is a great example of how to explain things simply without losing depth. I found it very helpful and engaging. The flow kept me interested throughout. Nicely written!

Like

This article felt refreshing and thoughtfully written. The tone was friendly and made the topic approachable. Each point was explained with clarity and purpose. I appreciated how well everything was organized. It made the information easy to understand. Great work on this post.

Like
bottom of page