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
344 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> ...
1
vote
1answer
34 views

SOQL with conditions on children

I'm unable to finish an easy query, I could use some help on this. I got a junction object called Creche_Zone_de_Tarification__c that links two objects (Account and Zone_de_tarification__c and that ...
0
votes
2answers
386 views

How to combine the two soql queries as a single SOQL query?

how to combine the two soql queries as asingle query? Contact con = [Select Id,Name,AccountId From Contact Where ContactId In (Select ContactId From User Where Id=:UserInfo.getUserId()]; List<...
0
votes
1answer
428 views

Relationship objects from the current object

I have 3 objects A, B and C. And B and C have lookup to A. I want to find all the objects which have lookup to the object A. I am able to get all the Child Relationships (using schemaMap.get('A')....
-2
votes
1answer
31 views

Optimize SOQL query

I have a condition where I need to get list of Contacts based on many conditions, which I'm able to do but now I need to limit the number of Contacts per Account. For the new scenario I need to ...
2
votes
1answer
30 views

Should the user input be escaped in dynamic SOQL when using binding?

Given the following query: public List<Account> selectById(Set<String> names) { String query = 'SELECT Id, Name FROM Account WHERE Name IN :names ORDER BY Name'; List<Account&...
0
votes
2answers
38 views

Cannot access the Parent field values from list<sObject> and Database.query

I have a dynamic SOQL that is being generated and then I am using database.query(querystring) to store the list of sObject in the dynamic sobject list. Here's the code : string queryString ='SELECT ...
0
votes
1answer
49 views

Most efficient way to get all child records for a specific record

I have an account record that I want to get every single possible child record - ideally as a list of IDs. Currently I am doing the following: for(Opportunity opp : [SELECT ID From Opportunity ...
0
votes
1answer
35 views

Can I convert this dynamic SOQL to static SOQL?

String queryString = 'SELECT Id,IsPersonAccount,RecordTypeId FROM Account WHERE LastModifiedDate < ' + Ke.Job_Start_Date_Time__c.formatGmt('yyyy-MM-dd\'T\'HH:mm:ss\'Z\'') + ...
0
votes
0answers
25 views

Unable to retrieve records from the dynamic sObject list

I have written some dynamic code for selected object listview. I want to show all recods which belong to the dynamic sObject but I am getting this error ( Invalid field Title for Contact ) for every ...
3
votes
1answer
589 views

How to use soql queries on multiple look up relationship object to retrieve specific data

I have 4 custom objects (as shown in the schema diagram). And they are associated using a lookup relationship. Now the objective of my question is to retrieve Product profile(product) for a given ...
0
votes
1answer
45 views

Can someone provide me the list of SOQL exceptions?

Can someone provide me the list of SOQL exceptions? a URL link which has all the exceptions and explanations. Thanks in advance
-1
votes
1answer
92 views

Error: Compile Error: Found punctuation symbol or operator '%' that isn't valid in Apex. at line 14 column 362

global class ABI_SFA_TAC_Removal_Batch implements Database.batchable<sObject> { // variable decleration. public String Query; /* Method Name: Start Description: This ...
3
votes
1answer
37 views

Is Contact othergeocodeaccuracy a legitimate field?

Many of our Continuous Integration builds just failed with hundreds of this error: System.QueryException: No such column 'othergeocodeaccuracy' on entity 'Contact'. Our code does describe calls ...
2
votes
1answer
58 views

Is it possible to rebind for dynamic SOQL in a more scalable way?

I came to the realisation that it isn't difficult to create my own String Interpolation, like this: public class XAP_UTIL_MapInterpolation implements XAP_UTIL_InterpolationIntf { String template; ...
1
vote
1answer
63 views

Forming a dynamic SOQL with multiple fields in WHERE clause

I have written a method to dynamically query an object and its fields. As I want to keep it configurable, a fieldset is used to provide with which fields to query, and also the object. The problem I ...
3
votes
2answers
1k views

create a map with keys = fields names and values = query result

I am trying to create a map from a result of a SOQL query, this map contains the name of the fields as keys and the values of the query as values for example: List accounts = [SELECT Name, Email ...
0
votes
2answers
259 views

System.QueryException: unexpected token: '<EOF>'

I have built dynamic query.but receiving below exception 01:16:56.0 (15683245)|USER_DEBUG|[335]|DEBUG|SetOfParentId--->{} 01:16:56.0 (15756602)|USER_DEBUG|[336]|DEBUG|Set1--->{} 01:16:56.0 ...
2
votes
2answers
683 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 ...
0
votes
0answers
18 views

get records based on recordtypeID and listviewID

I need to get records based on recordtypeid and listviewid but it is returning all records. I don't know where I'm doing it wrong.(it will return records based on listview but recordtypeid condition ...
1
vote
1answer
215 views

System.QueryException unexpected token

Trying to return all fields in object System.QueryException: unexpected token: '(' when I run the Invocable class at the parents = assignment public with sharing class AuditReportBulkifyClass { ...
1
vote
2answers
27 views

Query parsing error like clause

What is the correct syntax for a query that retrieves all Accounts that have __Civil_ in the Name? SELECT Id FROM Account WHERE (Name LIKE '%_Civil_%')
1
vote
1answer
68 views

How to find SOQL syntax error?

I have an error somewhere in my SOQL string but can't figure out where because the only message I'm getting is 'Unknown error parsing query' if I try to execute it in the Query Editor of the dev ...
3
votes
2answers
568 views

Workaround for SELECT * (SELECT all) in sfdx force:data:tree:export SOQL

In certain parts of our existing Apex code base, we've used dynamic soql in combination with object describe methods as a workaround to achieve the equivalent of SELECT * that's normally available in ...
1
vote
1answer
3k views

Multiple LIKE in SOQL

I have a batch class where I need to find all contacts with titles like director, cEO, etc. This should allow partial matches such as 'support director', 'sales director', I was trying this but is not ...
-4
votes
3answers
87 views

how to create dynamic query [closed]

List<Opportunity> opps = [ SELECT Id ,Name ,Amount ,CloseDate ,Stagename ,Near_to_Close_Date__c ...
0
votes
1answer
54 views

Need Help on Modifying Code [closed]

I found this example on a dynamic hierarchy for Accounts and I need help as to how to modify it to display an account hierarchy. I am unable to figure out why I recieve this error message when testing ...
0
votes
2answers
85 views

Trying to access unique records and the records of those unique records from the same table

select Id, Name from sumchans__AddressReportMATeam__c where Name in (select Name from sumchans__AddressReportMATeam__c group by Name LIMIT 3) I am not sure how to explain what I am trying to get here....
1
vote
2answers
135 views

Error encountered with usage of != or <> operating for SOQL query in batch class

I get the following error in Developer Console (logs) while executing this batch class with the following code snippet. 20:07:09:029 FATAL_ERROR System.QueryException: expecting a colon, found '(' ...
12
votes
3answers
23k 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 ...
0
votes
1answer
25 views

Construct Sforce.connection.query

I have a query for a JS button: ccid = sforce.connection.query("Select Id, Account__c from CCI__C Where IsActive__c = True AND Account__c ='" +AccountId+ "'"); It is working fine. Now I want to add ...
0
votes
0answers
107 views

Database.query is not returning data

I have a problem with the Database.query. Its not returning the data to the Apex class, But when I am using the query editor, its showing the correct data. My query is List<CM_Group__c> e = ...
0
votes
2answers
218 views

Dynamic Batch apex with sobject iteration

I have a batch apex which takes the record from source object (can vary like Opportunity, Opportunity line item etc) and paste the record into target object i.e Opportunity_Prod_Batch_Record__c (fixed)...
0
votes
1answer
174 views

How to get the Data Category in Select Dynamic Soql

I am trying to fetch Knowledge Articles based on Data Category through the below dynamic Soql query. String dynamicQuery = 'SELECT Id, Title FROM Knowledge__kav ' + ...
3
votes
1answer
1k views

SOQL Dynamic Query building using Map.get(List)

I have a doubt. Suppose I want to query on Account object filtering based on a given list of IDs. Below snippet works fine when I have a list of Ids. List<String> accountIds = new List<...
0
votes
1answer
51 views

How to query parent record picklist field value in dynamic WHERE clause

I want to develop a WHERE clause for a dynamic SOQL query in a utility class. The WHERE clause should lookup a parent record picklist field value.The relationship between Shared_Contact__c and Contact ...
13
votes
5answers
4k 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 Id,...
0
votes
2answers
33 views

SOQL query to identify Account names with out any number

I require to grab all account names which does not contain any number and display in the report. I am trying to query it using LIKE, but it is not working. My query - [select name from account where ...
0
votes
1answer
11 views

Trouble with lookup relationship parent query

I'm trying to construct a query that takes a specific Contract with a provided Id, and I want to fetch from this record, the related Order's, and their OrderItem's, So If I understand correctly I ...
0
votes
2answers
92 views

SOQL embedded select question

In our implimentation an Opportunity has a *.1 relationship with accounts and a *.1 relationship with brokers. An account is an entry to Object Account with Type = 'Customer'. A broker is an entry to ...
-1
votes
2answers
81 views

Unexpected Token Where

for(AggregateResult hier:hierarchy) { fld1.add((String)hier.get(Field1)); fld2.add((String)hier.get(Field2)); fld3.add((String)hier.get(Field3)); } string Soqlstr2='...
34
votes
5answers
32k 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.
0
votes
2answers
353 views

how to write Dynamic SOQL query using Not equal operator

MALFORMED_QUERY: Opportunity__r.LeadSource != 'Website'); ^ ERROR at Row:3:Column:89 unexpected token: ; SELECT Id, OwnerId, WhatId,Reminder_Date_Time__c, WhoId,Record_Type_Name__c, ...
-1
votes
1answer
39 views

Multiple group by problem [closed]

I need to find the name of the common records which have similar fields in them. For Example - I will create a vf page to dynamically take 3 fields for an object. And I need an Soql Query to search ...
2
votes
1answer
1k views

How to search for text in Rich Text area field in Apex

i want to search a text in Rich Text area field of a custom object. Since We can't use the RichTextArea field in the where clause of SOQL, I am looking for the way to search a text. Is there any way ...
3
votes
1answer
106 views

Select aggregate into Integer using Database.query()

So we all know we can put an aggregate directly into an Integer, like this: Integer countAccounts = [SELECT COUNT() FROM Account]; Is it possible to do the same thing, using Database.query()? ...
6
votes
3answers
345 views

Select into Map using Database.query()

So we all know it is possible to directly select into a Map, like this: Map<Id, Account> accounts = new Map<Id, Account>([SELECT Id, Name FROM Account]); Is it possible to do the same ...
1
vote
3answers
671 views

Like Operator is not working with Dynamic Variable in SOQL Query

Here I'm trying to perform LIKE operation in SOQL when I'm passing a variable dynamically the Query is not returning the results? List<string> companies=new list<string>(); List<...
-1
votes
1answer
31 views

Need to get schema field of a object while process [closed]

I tried as below mentioned code, for adding field value in dynamic way String type='Object__c'; Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe(); //getting required custom ...
1
vote
0answers
110 views

Bulkify dynamic query Batch Class?

I converted existing batch class that was processing single record into schedule/batch class that can process multiple records. But I got stuck in bulkifying the dynamic SOQL inside the for loop. ...