+ Start a Discussion
disturbed118disturbed118 

data binding in dyanmic soql queries?

how can you use data binding like

 

:data.keySet() in dynamic soql queries i.e database.query();

Pradeep_NavatarPradeep_Navatar

Use the get and put methods on an object to set or retrieve values for fields using either the API name of the field expressed as a String.

 

Schema.DescribeFieldResult f = Schema.sObjectType.Account.fields.AccountNumber;

Sobject s = Database.query('select AccountNumber from Account limit 1');

s.put(f.getsObjectField(), '12345');

 

Hope this helps.

sfdcfoxsfdcfox

You can do dynamic binding in the usual fashion, except you can't call function methods, so you would do this:

 

 

Map<Id,Account> accounts = Map<Id,Account>...

// before doing query...
Set<Id> accountIds = accounts.keySet();
Database.Query('select id,name,accountnumber from account where id in :accountIds');