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

learn more… | top users | synonyms

2
votes
2answers
95 views

How can I query parent to child with two child values and no other child values?

I have one parent "quote__c" and child object "Quote_line_item__c" .I want get the parent id with query some thing like this select id,(select name from quote_line_item__c where name='123' and ...
0
votes
0answers
29 views

how to get exact match of child records using a query?

I have Quote and Quote line items .Quote is parent and quote line items are child . I am developing one application . i am getting quote_line_item__c names as user input .I want to exact match of ...
4
votes
2answers
66 views

Apex CPU Time limit in Batch start() - is this a Query Timeout and how to cope with?

I have a Batch iterating over a large amount of records (with many fields) and 2 of their related child records. The start() method uses Dynamic SOQL to fetch them via QueryLocator to vary which ...
0
votes
1answer
65 views

How to dynamically assign objects in SOQL based on an event in the page?

Could you please help me on this? Existing Scenario: Records from two different objects ObjectA and ObjectB are displayed in a page as a news feed in ascending order of modifieddate. When click on a ...
0
votes
1answer
27 views

SOQL Includes with Field Value?

I'd like to add a FROM Account WHERE Clients_for_Job_Opportunities__c INCLUDES (AVTRRT__Job__c.Account.Name) line to my SOQL query but at the moment it looks like I can only add static values. So ...
2
votes
1answer
59 views

SOQL done right. SOQL-Injection secure

I was looking for some reassurance that all that needs to be done (and its best practice) when doing dynamic SOQL is to use escapeSingleQuotes. There was a query like this string query = 'SELECT ' + ...
0
votes
0answers
62 views

Issue in wrapper class

In the following snapshot we are fetching parent and child records using wrapper class.Selected child records should be displayed in selected course.But whenever i select child records only last ...
1
vote
1answer
61 views

Wrapper class Fetching all the Values

By using search function i need to fetch parent record and child record, the search function is happening in child record. Search function is fine But it is showing all child records in parent. this ...
2
votes
2answers
65 views

Passing array position as variable in dynamic SOQL

I want to pass a list position to my dynamic query, but it does not evaluate. have someone try something like this : ....... if(selectedType == Constants.settlementTypeAutre){ ...
4
votes
2answers
309 views

Concatenate fields in SOQL queries in the WHERE clause (no Apex)

I am trying to run SOQL statement in salesforce.schema tool of FORCE.COM the following query: Select c.LastName, c.FirstName From Contact c WHERE (FirstName+' '+LastName) In ('Good Name','Bad Name') ...
2
votes
1answer
77 views

How can I dynamically transverse dynamically SOQL'd SObject fields in Apex?

So, in my other post, I figured out for myself how to dynamically transverse SObject fields in Apex. But within the context of my work, there is a problem with the solution as it currently stands: ...
2
votes
1answer
183 views

Query Multi-Select Picklist in Apex with Visual Force Page

I'm having some difficulty figuring out the correct way to do this. If I have a visual force page with a multi-select picklist and I need to run the selected values through a query. The issue is I do ...
1
vote
1answer
61 views

SOQL for getting CaseComent for a case

I want to get the associated CaseComment's CommentBody for a list of cases. String queryFields = 'Id, Subject, CaseComment.CommentBody'; List<Case> cases = Database.query('select '+ ...
1
vote
2answers
208 views

get account name from a soql query on case

String queryFields = 'Id, AccountId, ContactId, type'; List<Case> cases = Database.query('select '+ queryFields +' from Case'); for(Case c: cases){ System.debug(c.AccountId); } Instead of ...
2
votes
2answers
264 views

Dynamic soql : Unexpected token '{'

Set<Id> sId = new Set<Id>{}; sId.add('a0df000000063A9AAI'); sId.add('a0df00000006P2cAAE'); String squery = 'SELECT Id, Name FROM Engagement__c WHERE Id IN:'+sId; List<Engagement__c> ...
3
votes
2answers
344 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 ...
7
votes
2answers
149 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
137 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
582 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 ...
1
vote
1answer
67 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
63 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
235 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
69 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
328 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
320 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
229 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
256 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
705 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 ...
7
votes
2answers
2k 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
474 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
57 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
254 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
98 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
469 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
760 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
40 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
700 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
154 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
430 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 ...
5
votes
3answers
2k 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
1k 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
349 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
423 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
2k 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 ...
14
votes
3answers
5k 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
184 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
393 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
418 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
101 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 ...
5
votes
1answer
523 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, ...