Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [dynamic-soql]

Dynamic SOQL refers to the creation of a SOQL string at runtime with Apex code.

9
votes
1answer
17k views

How to use the escapeSingleQuotes method?

I'm trying to use this method in a dynamic SOQL query. Follow the sample code: public static String getRowById(String sobjName, id id) { String query = 'SELECT '; Map<String, ...
26
votes
2answers
5k views

Bind variable with dotted name not working in dynamic SOQL

As mentioned in this answer, it's possible to use bind variables in dynamic SOQL queries. This seems like a great way to avoid SOQL-injection, and to build a query string once but use it multiple ...
3
votes
1answer
5k views

Retrieving value using dynamic SOQL

This is my query... List<Opportunity> opportunities = Database.query('SELECT OwnerId, Amount, Probability, ExpectedRevenue ' + mycustomatt + ' FROM OPPORTUNITY ' + ' where isClosed = false'); ...
8
votes
1answer
2k views

Field Sets & Dynamic DML & Describing Fields Included in Field Set

I am attempting to write generic code which will use a fieldset, allowing for dynamic creation of a query. This bit is documented well enough in dynamic DML examples from SFDC. In addition to the ...
6
votes
1answer
2k views

Integration - Outbound Messages - configure Endpoint URL dynamically!

Hello guys! Scenario: I am sure all of you come across this everyday if you do integrations. I have 2 sets of machines (Training and Production). The outbound messages in prod. instance point towards ...
1
vote
2answers
2k views

Can we query hidden fields in apex?

There is a field named "Email Opt Out" in the contact object. Can we query this field and put in the filter condition if the "Email Opt Out" field does not have both "Field-Level Security" and "Field ...
9
votes
2answers
8k views

What makes a field not groupable

I'm trying to use an aggregate query, but one of the fields I want to group by is not groupable (saw it in the soql error and then verified groupable=false in the metadata). It's just a number field ...
3
votes
5answers
6k views

Dynamic SOQL variable binding not working for multiple records

Am building a dynamic SOQL where I am using a list of strings that represent record ids, here's an example similar to my class: String q = ''; q += 'SELECT Id FROM' + object; q += ' WHERE Id IN :...
6
votes
2answers
24k views

use string array in IN clause in dynamic soql

I have an array of strings i'd like to use in the IN clause of a dynamic soql query. if i wasn't building the string at runtime i could simply use (from the SF docs): String[] ss = new String[]{'a', ...
7
votes
1answer
2k views

CurrencyIsoCode - Auto included in query results, except for test cases

I've implemented some functionality around MultiCurrency in a Managed package. Since it needs to be able to support non-multi-currency orgs, all references to the CurrencyIsoCode field are done using ...
2
votes
2answers
287 views

Less verbose dynamic +=?

I'm trying to do something like this: sObject.Custom_Field__c += myNumericVar; But I'm using dynamic SOQL, so I can't hard-code the name of the fields. The following code works, but it's really ...
4
votes
2answers
2k views

SOQL inline query vs dynamic query

I just wanted to know weather to use inline query or dynamic query as my daily practice. I know in some cases we have to use dynamic query. But as routine practice which one to use. Any thoughts?
69
votes
4answers
23k views

Elegant way to convert Set<Id> into String for Dynamic SOQL IN comparison

When I have a Set of Id's and I want to do a dynamic SOQL query that I want to use it in for an IN comparison, I have to convert the Set to string in the format of: ('id1','id2',id3',...) The way I ...