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

learn more… | top users | synonyms

3
votes
2answers
111 views

Dynamically create SOQL query from sobject

I have an SObject say Account which has some not null fields. I want to select all the accounts matching those values. Is there a way I can create a dynamic SOQL query for this. Suppose the Account ...
5
votes
1answer
52 views

How to execute a dynamic SOQL query with a variable number of “in” terms?

I understand from answers like this Bind variable with dotted name not working in dynamic SOQL that binding Apex variables into dynamic SOQL is more limited than into static SOQL. I want to write ...
4
votes
1answer
66 views

Soql-builder - Datetime issue

I have been trying to write a dynamic soql query by using soql-builder http://richardvanhook.com/2010/04/11/soql-builder/ But, I am stuck while assigning date as criteria while constructing the ...
2
votes
2answers
201 views

Line Breaks Not Allowed in String Literals

I have a SOQL query below that works in the Force.com Explorer but when I implement it into my dev org Visualforce page, I get the following result: Error: Line Breaks not allowed in string literals ...
0
votes
1answer
34 views

dynamic query to pass email field value

How to frame the below dynamic query. Opportunity_User__c field has value in format of "test@gmail.com". Now i want to retrieve all the opportunities having that value using dynamic query. ...
2
votes
1answer
42 views

SOQL CALENDAR_MONTH() and WEEK_IN_MONTH() Confusion

I have a SOQL filter on a DateTime field as below SELECT fieldList FROM myObj WHERE CALENDAR_MONTH(myDateTimeField)=12 AND WEEK_IN_MONTH(myDateTimeField) IN : (4,5) AND myDateTimeField = THIS_YEAR ...
2
votes
3answers
95 views

Dynamic SOQL binding

I have some filter conditions on my page and when user selects those filter conditions I need to display all those records that satisfy those filter conditions like suppose these are the filter ...
-1
votes
1answer
50 views

apex trigger issue with dynamic soql

custom object: schedule_c fields: Runway_C and date_C Runway_c is a picklist field having track1 and track2 values. date__c field is datetime field. i having the the records in schedule object e.g ...
0
votes
1answer
111 views

how to bind string to date in soql query?

visualforce page: <apex:inputText value="{!inputText6}" size="20" id="teja2" onfocus="DatePicker.pickDate(false, 'page1:form1:teja2', false);" /> <apex:inputText ...
1
vote
1answer
140 views

Need to build the dynamic soql query in trigger

custom object: schedule_c fields: Runway_C and date_C Runway_c is a picklist field having track1 and track2 values. date__c field is datetime field. i having the the records in schedule object e.g ...
1
vote
2answers
123 views

How to make soql query dynamic

trigger runwaynew on Schedule__c (before insert, before update) { Map<string,List<Schedule__c>> ScheduleMap = new Map<string,List<schedule__c>>(); set<Date> ...
1
vote
1answer
130 views

System.QueryException: error when button click second time?

vf page: <apex:page showHeader="false" sidebar="False" controller="textInputsCon" applyHtmlTag="true" > <apex:form > Input Text1 <apex:inputText ...
1
vote
3answers
208 views

How can I compare datetimes in a SOQL query to return a list to a Visualforce page?

I want to display a certain group of Events in Visualforce page - my query to only get Events that were created/modified after the Event happened - first tried with a custom field, but this proved ...
6
votes
2answers
443 views

Can a SOQL query selecting all columns be generated at runtime?

It seems like SOQL does not have an equivalent to SQL's "SELECT * FROM ..." (If SOQL has this syntax, show me and I will mark that as the answer.) To get around this limitation, I have been using a ...
4
votes
2answers
206 views

I am getting an error when i run my dynamic SOQL line 1:213 no viable alternative at character ' '

I am generating a dynamic SOQL but when I run my SOQL I am getting an error 1:213 no viable alternative at character ' ' My code /* * admin approval panal */ public class ...
0
votes
1answer
39 views

sorting trailing 12 months values

I want to show a chart which shows revenu trend of trailing 12 months. In my dataset, I have Month and Year in String format i.e. month has values like "1", "2" etc and year has values like "2013", ...
6
votes
3answers
137 views

How do I SOSL across objects, matching all records with FIND clause?

To all the expert SOSL gurus lurking out there, I thought this will be an interesting one: I have some SObjects of different types and I want to return their Name values in a single query. In ...
2
votes
1answer
68 views

Dynamic invocation (or emulation) of the hierarchy custom setting getInstance() method

I have a requirement to avoid any compile-time dependency on a managed package. Dynamic SOQL, SObjectType and SObject allow me to do this cleanly for normal objects. But now I need to access a public ...
3
votes
1answer
245 views

How to handle null value of AggregateResult

I am having a doubt while writting the code. I am using AggregateResult while writting a query. If AggregateResult is not equal to null then I'm able to write my logic and it is working fine. But ...
9
votes
1answer
365 views

Getting “__r” relationship name from Schema.SObjectType.Fields

Say I have a master-detail relationship between two objects, Schematic__c and Part__c. I can SOQL query the master from the detail: [SELECT Schematic__r.Name FROM Part__c] If I'm building a query ...
1
vote
1answer
37 views

WEEK_IN_MONTH(DateTime) not working

I'm trying to retrieve some records by applying a filter for weeks(for a selected month). To doing this I'm using WEEEK_IN_MONTH(dateTimeField) SOQL function. But when this filter applied, result set ...
5
votes
4answers
468 views

Dynamic SOQL How to bind date?

soql = 'select A__c,EmplId__c, B__c,Date__c from Transaction__c Where Transaction__c.name!=null'; if (!branch.equals('')) system.debug('test br1'); soql += ' and A__c LIKE ...
3
votes
1answer
116 views

Can you sort a soql query based on number of child records you have

I have a soql query private static String selectQuery = 'select ...
9
votes
1answer
285 views

Get the sObjectType of a field dynamically

I have a field Board_Name__c that is a lookup from Opportunity back to Opportunity. How can I dynamically find out that Opportunity.Board_Name__c references the Opportunity sObject while ...
4
votes
3answers
601 views

How to use Count() in SOQL

I have a custom object. This custom object has a field Cabin_Type__c, which has values of Twin and Luxury. There is another field Deck_Type__c which is just the number of the deck such as 1,2,3,etc. ...
3
votes
2answers
690 views

Filtering by Long Text Area field in SOQL

I'm working on a custom search page, which will search through the fields of the Project object. I use dynamic SOQL query similar to that: String query = 'SELECT Name, Status__c ... FROM ...
4
votes
1answer
227 views

“FeedItem requires a filter by Id” exception despite filtering by ID

A client is getting an exception whenever they insert a FeedComment in their org. There is a trigger on FeedComment (api 25.0) which calls a static method in a class (api 26.0) to get a list of ...
8
votes
3answers
277 views

Querying Randomly

I am looking to implement a raffle against the user table, where one is picked at a random amongst a pool of 100k+ users. How would you perform the random query without a batch job or modifying the ...
7
votes
1answer
1k views

SObject row was retrieved via SOQL without querying the requested field:

I am getting this error with the code below. I've looked into the other cases on here. In my case I am referring to a relationship name (__r) which I am assuming is pulling correctly. It's a field ...
13
votes
3answers
3k views

Use Set<Id> in dynamic SOQL IN-clause in method without Database.query()

I know and love that Apex is automatically converting Set to a valid SOQL string when it is used referenced like Set<Id> ids = ... String soql = 'SELECT ... WHERE Id IN :ids'; and passed to a ...
3
votes
1answer
157 views

problem with dynamic SOQL

I am trying to do a dynamic SOQL for this i am adding a user id to it but while it is SOQL it is getting an error that : no viable alternative at character '\'. My SOQL look is like this SELECT ...
2
votes
2answers
256 views

Dynamic SOQL - Multiple variables [duplicate]

I would like to pass two variables to my SOQL Where clause. Can someone give me an example how this is done in Apex. My objects are custom objects. Variable1 Variable2 Example in SQL: 'Select ...
6
votes
2answers
292 views

How to take a filed value after dynamic SOQL

I am trying to get field value from a dynamic SOQL result. Here i have a object where end user need to enter the field name which he need. I am SOQL it like this: UserprofileSOQL = ...
3
votes
1answer
88 views

Best approach for monitoring events dynamically?

I want to monitor for inserts and updates on objects over a specified period of time. I don't know in advance which objects I need to monitor. My constraints are the govenor limits and accuracy. I ...
4
votes
1answer
257 views

QueryException: Non-selective query (it is selective)

I am trying to query a Custom Object called Lead_Assignment__c based on some criteria. Original query below: List<Lead_Assignment__c> leadAssignments = [ SELECT Segment__c, Queue_Name__c, ...
4
votes
2answers
752 views

trying to get a count of records(records more than 50000 in object) in one object through apex class

Trying to get a count of records(records more than 50000 in object) in one object through apex class(Getting limit Exception). Looking for any alternate solution. I used ...
4
votes
1answer
269 views

Any good workarounds to QUERY_TOO_COMPLICATED error for dynamic SOQL?

When running a dynamic query with certain formula fields I get the following error: System.UnexpectedException: Query is either selecting too many fields or the filter conditions are too complicated. ...
6
votes
2answers
151 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
2answers
326 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 ...
3
votes
1answer
710 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 ...
0
votes
0answers
89 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
339 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 ...
6
votes
3answers
507 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 ...
2
votes
1answer
507 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 ...
2
votes
3answers
583 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 ...
9
votes
2answers
579 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 ...
2
votes
3answers
598 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
112 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
224 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 ...
5
votes
1answer
367 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 ...