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

learn more… | top users | synonyms

1
vote
2answers
38 views

Accessing the fields of Database.query() results

Database.query(query) returns sobjects. I want to access each fields in this sobject to check the value on each field. How is this done in controller?
10
votes
4answers
450 views

Howto wildcard SELECT * to query all fields of objects in APEX?

I have created sObject and I need all the fields and I have many. Is there a way I can directly get all of them rather then typing each one of them.
1
vote
1answer
45 views

Offset value as a variable

I have to put an offset value in a query as a variable.Can someone please help here?Please my code snippet here. Integer lim=101; for(Integer i=0;;i+lim){ Integer j=i-1; return ...
0
votes
2answers
72 views

Apex CPU Time limit exceeded error

I have a batch apex class that is facing CPU time limit exceeded error. Can someone please help me to by pass this error here? Please find my batch apex here. global class Account_chk_batch ...
0
votes
1answer
27 views

Programmatically determine relationship between two sObjects and generate result

I have an application which allows the user to specify a geography object and field. For example User's country field Account's State Field Now for Leads the system needs to dynamically determine ...
2
votes
1answer
64 views

Dynamic SOQL for Cross-Objects

I am wondering if there is an easy way to dynamically query accounts based on the account having the primary FSE name attached to it. The Primary_FSE__c field is on the Installed Product Object, which ...
0
votes
1answer
73 views

query for multipick list values

I want write down query to fetch value depend on Channel. when user select Channel value is equal to Partner(pick list value) and then display value in dependent pick list for Partner Level which ...
0
votes
1answer
41 views

Not Queryable field issue

I have to query on a non-queryable field here. Can someone suggest a workaround for this? Please find my code below. trigger PM on Account (after update) { for ( Account acc : Trigger.New ) { ...
1
vote
2answers
106 views

After update trigger issue

Please find my code below. trigger PM on Account (after update) { for ( Account acc : Trigger.New ) { List<Product_Metrics_vod__c> listCon = [Select ...
1
vote
2answers
61 views

SOQL_SOSL Injection Issue Solution

Here I have done get;set; with "selectedEvent" which is a selected value of the Picklist, which can be TODAY, THIS_WEEK, THIS_MONTH or NEXT_MONTH which are standard things which I can use in SOQL to ...
3
votes
2answers
176 views

Grouping in Visualforce Charts

I have created a visualforce charting barSeries and it renders the results that I want aside from products with values of zero for the month. The chart is a repeat business report that is meant to ...
2
votes
2answers
118 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
52 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
140 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
81 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 ...
1
vote
1answer
42 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
103 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
71 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 ...
2
votes
1answer
121 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
93 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
666 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
92 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
626 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
124 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
477 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
498 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
605 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
271 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
168 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
910 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
79 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
80 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
393 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
75 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
443 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
401 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
292 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
331 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
1k 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 ...
8
votes
3answers
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
685 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
66 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
422 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
110 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
604 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 ...
10
votes
1answer
1k 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
43 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
899 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
187 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
563 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 ...