Questions tagged [dynamic-soql]

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

Filter by
Sorted by
Tagged with
6
votes
2answers
537 views

Check if a .txt file of IDs all exist in Salesforce

I receive a .txt files of type ID, e.g. 003U000000PL9LN, 001U000000PL9LM, a1fU000000PL9LO. I need to check if these IDs correspond to valid objects within Salesforce. I have a List of IDs in Apex. ...
1
vote
3answers
2k views

SOQL query by data type

Is it possible to query fields by datatype? I need to query all email fields from different objects. Email field names are different on each object and not known in advance. So I am trying to query by ...
6
votes
1answer
7k views

How to Search a text in all fields in all objects and return all values?

Can I find a string from all fields from all custom and standard objects and return the data (all field data) of all the records that matches for all the fields of those objects?? Also is there an ...
1
vote
2answers
677 views

Wildcard search multi select fields

Is is possible to use wildcards in where statements on multi-select fields I tried a simple Select Id, Name from Positions_c where Industry_c includes(:selectedIndustry) this works but if i want ...
1
vote
0answers
2k views

Trying to determine fields I want to set dynamically rather than hardcode - very close / not possible

I am messing around with the dynamic nature of Salesforce. I want to clone Opportunity into a custom object. It's a very easy requirement in itself. What I am trying to do is make if completely ...
7
votes
3answers
3k views

Unable to perform a COUNT() query on object with many million records

I have a custom object with around 25.000.000 records and need to perform a single count query to find those records where a field has a certain value. I could get none of the following queries to ...
6
votes
2answers
3k views

Dynamic SOQL Queries and Managed Namespaces

If I create a dynamic SOQL query (via strings, to be used with Database.query) in an unmanaged code environment, and then the code is converted to a managed environment, are namespace considerations ...
3
votes
3answers
2k views

Dynamically display results from an unkown SOQL query

I want to do some investigation of how the data looks in my Salesforce org, so I'd like to have a simple Visualforce page that takes an query string as an input and then display the results in a ...
10
votes
2answers
5k views

How do you dynamically select fields in for loop query?

Something has been bugging me for a little while now, and I can't seem to find the answer anywhere... When working with large queries, it is a good idea to use a for loop to iterate through the query ...
3
votes
3answers
8k views

How can I do a substring (or string operation in general) on a Schema.SObjectType?

Please ignore any syntax errors I may have made while typing the following up: Schema.SObjectType t = custom__c.sObjectType; // The following succeeds String query = 'select id, name from ' + t + ' ...
2
votes
1answer
285 views

Field missing using apex-lang SoqlBuilder

I'm using Apex-lang to build queries. http://code.google.com/p/apex-lang/ problem: A custom lookup field won't show up in the generated query. If I duplicate the SoqlBuilder class and use the new ...
2
votes
3answers
1k views

Map of API name and value pair..?

I want to create a map of apiname and value pair..please help... i want record value...like if apiname of opportunity field is name..then i want record value..ie opportunity name... for eg Map<...
7
votes
1answer
3k views

How to implement a generic DAO object for Service pattern with Apex?

Considering advice given for DAO objects or Service pattern from What is a good set of coding conventions for Salesforce development?, I'm wondering how can they be made generic enough? Some generic ...
3
votes
2answers
1k views

Avoiding casting with dynamic SOQL

According to this http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_dynamic_soql.htm I should be able to avoid casting using dyanmic soql However when I try: opportunity = 'select ...
7
votes
5answers
1k views

Trying to LIMIT a SOQL Statement based upon projected Heap size

THE GOAL: Return as many rows as possible from a Remote method without hitting Heap limits. We have a Visualforce page calling into a @RemoteAction method in Apex to return sObjects to the page. The ...
0
votes
3answers
1k views

Using a variable in dynamic sql [duplicate]

I have a set of IDs I wanted excluded from a Task query. I need to use dynamic sql for this. I try: Set <ID> unwantedIds = ... // ids I don't want. String query = 'select Id, ThirdPartyId__c, ...
4
votes
1answer
863 views

Build String Similar To That is Allowed in Database.query

Well Salesforce Database.query has a unique feature that allows us to append the bind variable inside the Query string. All the variables that is included in the query string automatically calculated ...
9
votes
1answer
18k 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 ...
10
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
26k 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', ...
8
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
295 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?
71
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 ...