The Stack Overflow podcast is back! Listen to an interview with our new CEO.

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
2
votes
1answer
207 views

Group by part of string in SOQL

Is there any way to Group By part of string in SOQL. For example something like: Select Id, Name from Object__c group by Name.substringBetween('.','.') So query by part of a string field and not ...
3
votes
2answers
135 views

How to keep soql out of loop, and still be functional

I have this Schedulable Class that finds all Email Campaigns of a certain age and sends that age to an external service. I am pretty sure I am doing it wrong. First I want to pull the values for the ...
0
votes
1answer
78 views

Setting Dynamic Query Criteria Based On a Variable

I need to define a clause for my dynamic SOQL query, based on the value in my userRegion variable, by adapting the query from this answer. When I try to use String queueOwnerRegionClause = ( ...
1
vote
1answer
480 views

Phone numbers to search irrespective of the format stored in Database

I have the requirement where I need to search a phone number in the UI like => 8405678978. So if I am passing the number in the UI like this 8405678978, it is not querying from the database as in the ...
1
vote
1answer
325 views

query the accont records based on distance

public String distance=50; String units='mi'; //lat,lon has latitude and longitude values List <Account> Addd =database.Query('Select Name,Phone,BillingLatitude,BillingLongitude from Account ...
0
votes
1answer
198 views

Need help in dynamic soql Formation

I have a requirement where in dynamic query i have to change the format of a string.Below is the way i have tried i am getting following error after adding getTempStringFormatValue method in the below ...
1
vote
1answer
1k views

Want to fetch the child relationship name from the Lookup field name?

I am developing a functionality where I am to check for the presence of Child records, before executing a part of code. I can't do hardcoding since my code is going to be a part of a managed package, ...
0
votes
2answers
91 views

Created a dynamic string and want to fetch list size on the basis of that string [duplicate]

I have an object that is having multiple child objects. I want to perform certain actions only if the current record has child records associated with it. For this I am checking the related list's ...
1
vote
2answers
2k views

An unexpected error occurred. Please include this ErrorId if you contact support: 76743200-1017657 (1358022652)

Using the below code, I get this error message: An unexpected error occurred. Please include this ErrorId if you contact support: 76743200-1017657 (1358022652) String sql = 'SELECT Id, ...
2
votes
3answers
404 views

Building dynamic query AND/OR

My question is continuation from here This is the sample SOQL query which I'm trying to build dynamically and I have dozens of fields, it has AND OR My question is: I'm trying to figure out how to ...
0
votes
3answers
5k views

Building dynamic query string where 'AND' clause concatenation

EDIT: One thing I forgot to mentioned is that, there is a condition what fields to be added to WHERE clause for an example: Match1 = the where clause should be `emp_name__c, emp_num, emp_code` Match2 ...
1
vote
2answers
361 views

build dynamic SOQL condition

How to build the above query condition dynamically (i.e.) if same field label like "email" should be in OR conditions remaining labels should in AND condition eg... where [((email=:'test@gmail.com')...
1
vote
1answer
118 views

Create Dynamic Table On the basis Of 2 Objects [closed]

There are 2 objects one obj1 and obj2 I have to create dynamic table in visualforce page in which if new record is inserted to the obj1 then one row should be added to table and if one record in obj2 ...
0
votes
1answer
109 views

unexpected token found -null in dynamic query when i ran my test class

class method:- Error on this line lstofSobj = Database.query(query); -Unexpected token null public void deleteRecord(){ //system.debug('typeName::::'+typeName); ...
1
vote
3answers
4k views

System.QueryException: expecting a colon, found 'setids'

I keep getting the error: System.QueryException: expecting a colon, found 'setids' Why do I get this error? How can I fix it? public Database.QueryLocator start(Database.BatchableContext context) ...
-1
votes
1answer
411 views

Warning when using fflib_QueryFactory

When performing a sub query, I get the following message: WARN|fflib_QueryFactory.subselectQuery(Schema.SObjectType) is deprecated and will be removed in a future release. Use fflib_QueryFactory....
5
votes
2answers
309 views

Record Not Returned in Query in Managed Package

I think I'm going to have to find someone internal for this one, but posting to see if anyone has any ideas about this at all. The Problem We've got code in a managed package that's querying for ...
0
votes
1answer
778 views

soql query on case

I actually need a soql query to fetch those case records in which the incoming emails from email to case are more than one in the related list of case. One criteria is that the subject of the email ...
1
vote
1answer
3k views

Escape Sequence Single Quotes Error

I am creating a dynamic query. string s = '%' + searchText + '%'; string query = 'Select name, ShippingCity, ShippingState, ShippingCountry, rating, type, Industry, ownerId From Account Where name ...
1
vote
2answers
532 views

unexpected token: IN in dynamic soql

I have written a code which will give my dynamic soql and using this soql my execution will work. But i am getting this erro unexpected token: IN41 Below is my code Code public class ...
0
votes
3answers
196 views

Dynamic query Help?

I have created a custom Setting as "ContactSetting" and one field as "Agents_Field_Name" So my custom setting is like: Name:FirstName Agents_Field_Name:FirstName I am trying to query Contact record ...
1
vote
1answer
38 views

Capturing the Lead deletion log using dynamic apex

I am trying to create an entry in the deletion_log__c object before the lead record gets deleted. I would like to capture all the lead field names along with values in the deletion_log__c object with ...
0
votes
1answer
150 views

Risks of replacing SOQL query with QueryLocator [duplicate]

I used to have this block of code in a widely used method: SObject[] ls = Database.query(q); SObject[] children = new SObject[]{}; for (SObject l : ls) { for (SObject c : l.getSObjects('...
3
votes
2answers
435 views

Inconsistency with error “Aggregate query has too many rows for direct assignment”

I have a Box__c record with 100 Doors__r, 104 Motors__r, and 0 Wheels__r. ISSUE #1 I am getting the error System.QueryException: Aggregate query has too many rows for direct assignment, use FOR ...
0
votes
1answer
78 views

save error :unknown property 'DataInsert.fields'

Here is my apex class: global class DataInsert { // property declarations Set<String> fields ; global PageReference doInsert() { // other logic ...
0
votes
3answers
71 views

How to separate the required fields from Custom Object record?

I'm posting this question previously but i'm not achieving my goal for that i posting again I have a custom object called Incident__c. and it has some fields Imtpact__c Incident_state__c ...
1
vote
2answers
261 views

Query if Lead not modified in the current month?

Is there a way to query if a Lead has not been modified in the current month by using LastModifiedDate?
-2
votes
2answers
799 views

How to search a custom object using one or more input pick list fields from a VF page and display the result(s) in a pageBlockTable

accept the input as strings (in an extension), build & execute the query, populate a list element, display the list. Please give an example.
4
votes
2answers
2k views

Dynamic query in a for loop

I need to retrieve the CreatedDate of the last record creates of every custom object. But the only way I find to do it is by doing a dynamic query in a For or loop. But I’m, of course, limited to 100 ...
2
votes
2answers
836 views

Variable text string for SObject get method?

I want to use a variable string rather than a hard-coded string in my get method. For example, for every Field in Object A there will be a record in Object B and the record name is the field api name ...
4
votes
1answer
416 views

Is IN operator equivalent to Equal operator in SOQL when binding a list variable?

While testing some SOQL queries I noticed that the Equal operator behaves like the IN operator when using a list bind variable All the queries below run without any error and return the same result ...
6
votes
3answers
2k views

Possible to use bind :variable inside SELECT clause?

I cannot use the String[] ss inside the SELECT statement. It is giving me errors: unexpected token: ':' Code public void getSubscribers(Id listId){ String[] ss = new String[]{'Id', 'Name'}; ...
1
vote
1answer
585 views

Unexpected token '(' error batch apex

global Database.QueryLocator start(Database.BatchableContext BC) { String query = 'select id,ParticipantName__c,EpisodePoPEndDate__c from BPCIAe__c where id in :CHildParentMap.keyset() OR id in :...
24
votes
1answer
564 views

SOQL bind variable scope behavior

After I posted this question, I found a similar post that seemed to answer it: Variable scope - database.query() has access to variables not in scope. I'll leave this in place for now, as I am not ...
4
votes
2answers
2k views

Bind a List variable in a Dynamic SOQL Query

Code 1 List<String> accNameList = new List<String>{'Acc1','Acc2','Acc3'}; List<Account> accountList = Database.query('SELECT Id FROM Account WHERE Name IN:accNameList'); Code 2 ...
0
votes
0answers
37 views

“System.LimitException: Too many SOQL queries: 101”

I have SOQL on 17 objects to delete sharing Need help since we cant use SOSL on _share__c objects list<Lease__Share> deleteLeaseShare = new list<Lease__Share>([select id from Lease__Share ...
2
votes
2answers
1k views

Query sObject type with dynamic name

Can I create a list variable dynamically in Saleforce? Like this: String objectName = 'Noise_Dictionary__C'; List<ObjectName> lstObject = new List<ObjectName>([select id from ObjectName ...
0
votes
1answer
169 views

How to remove the query size limit for VF page

I'm using standard set controller, with dynamic search options on VF page. Now soql limit 1000 it works perfect. But i've to remove the soql querye limit. I.e. I can be able to fetch 70000 record ...
1
vote
1answer
262 views

SELECT ActivityHistories For Any SObject

I am writing a code which supposed to process a list of ActivityHistories for any SObject which supports them (like Opportunity, Account, etc). And at that point it's impossible to know what is the ...
0
votes
2answers
194 views

How to use list index in Soql

list<string> lst=new list<string>(); lst.add('name'); system.debug('lst[]'+lst[0]); system.debug([select count() from account where lst[0]!='' limit 1]); I am getting below error Line:...
4
votes
1answer
1k views

Check if an SOQL query is valid without actually executing it

I'm building a system where a user will be providing me with a query through a UI. This query will then be used in an Async Apex Job, by passing it as a param to Database.getQueryLocator in the start ...
0
votes
2answers
837 views

How do write a SOQL join between contact and custom object?

I need to get contacts with related table "Candidate_Farm_Assignment_c", the thing is i want that it will pull only the records that have a specific value from "Candidates_Farms_Assignments" SELECT ...
0
votes
2answers
23 views

Error: dailyHLAReportDashboardController Compile Error: expecting a right parentheses, found 'Active' at line 6 column 201 [duplicate]

I am trying to query counts of an custom object records but i also need to filter out the records. so when i am using single quotes for where clause getting error as: Error: ...
4
votes
2answers
1k views

Dynamic Query / escapeSingleQuotes And “no viable alternative at character '\'”

Read all the articles, tried most everything but cannot find a solution other than faith that users will not enter malicious data but: I am trying to create a user entered query filter but when I use ...
0
votes
1answer
252 views

Dynamic select KnowledgeArticleVersion by Language

I have the following code: List<KnowledgeArticleVersion> articles = [SELECT Title, UrlName, FirstPublishedDate, Summary, ArticleType, LastModifiedDate FROM ...
0
votes
2answers
89 views

Soql query is not displaying the values of the Child object record

I have soql query which will have subquery to get the value of the child object values. However there is no error in the query but the values that suppose to display is displaying as null in VF page. ...
2
votes
1answer
385 views

Select names of multiple sObject types in one query

I have a set of record id and I don`t know types of this records. Can I select only field name for this record ids in one query? I thought something like that: List<ProcessInstanceWorkItem> ...
0
votes
2answers
2k views

How to query multiple Child object of a parent in single soql query

I have to bring the values of a multiple child object of a Parent object in single query, I tried the following method , however for query one child object as a first step it throws me the following ...
0
votes
1answer
80 views

Performance issue for searchable 500+ fields

I haven't work on something like this before but what are the performance implication whether using SOQL or SOSL 500 fields+ (fields will be added dynamically as the application grows) and having 800K ...
0
votes
2answers
78 views

how to build dynamic query

Hi I have to query a record information of the customer. Based on the number of Order the customer submits it should retrieve the same. Please find my query below In the above code i am using the ...