Tuesday, 27 December 2022

Dynamically Pass Bind Variables to a SOQL Query (Spring 23)

 New Database.queryWithBinds, Database.getQueryLocatorWithBinds, and Database.countQueryWithBinds methods, the bind variables in the query are resolved from a Map parameter directly with a key rather than from Apex code variables.

ex :

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);


No comments:

Post a Comment