Tagged Questions

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

learn more… | top users | synonyms

4
votes
2answers
41 views

Order Field by List in SOQL SELECT

I have an aggregate query on the Lead object. The query returns a list of Leads grouped by website (custom field) in a specific order based on a MAX of a date attribute. Say once we iterate through ...
1
vote
1answer
48 views

Getting error “System.LimitException: Too many query rows: 50001” what i do in this case.

i tried below resolutions but no any worked... REsolution: If your controller does not have any DML operation than you can easily solve above two salesforce governer limits using the attribute ...
10
votes
4answers
263 views

SOQL query to return records with numeric values

I'm trying to write a dynamic SOQL query to get an object's record that has numeric value in a particular field. I'm trying to do something similar like below: Account acc; queryString = 'SELECT ...
3
votes
1answer
68 views

Is it possible to get record data and SObject metadata in a single API call?

We're trying to handle custom fields for things like Tasks. Is there any best practice for doing things dynamically? We've made a webapp that lets users from various organizations connect. So it's not ...
1
vote
2answers
46 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
526 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
51 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
159 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 ...
1
vote
1answer
45 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
76 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
84 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
49 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
116 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
69 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
249 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
125 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
59 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 ...
5
votes
2answers
177 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
86 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
49 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
143 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
74 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
163 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
99 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
821 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
107 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
706 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
178 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
631 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
614 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
719 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
363 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
179 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
1k 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
85 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
96 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
452 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
79 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
508 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
445 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
316 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
368 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 ...
9
votes
3answers
3k 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
758 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
69 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
465 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
124 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
680 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 ...