Questions tagged [dynamic-soql]

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

0
votes
2answers
23 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
29 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
31 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
22 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
565 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
43 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
46 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
35 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
56 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
43 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 ...
2
votes
2answers
938 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
202 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
667 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
16 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
179 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
58 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 ...
0
votes
1answer
405 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
2answers
517 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
75 views

how to create dynamic query [closed]

List<Opportunity> opps = [ SELECT Id ,Name ,Amount ,CloseDate ,Stagename ,Near_to_Close_Date__c ...
0
votes
1answer
48 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
56 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
133 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
22k 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
84 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
134 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
141 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
46 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
32 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
61 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='...
33
votes
5answers
31k 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
282 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
35 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
100 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
307 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
567 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
24 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
84 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. ...
0
votes
1answer
174 views

How to check if sObject/sObectType is supported in SOQL?

I'm working on a SOQL query builder which should show all the Objects of an Org which are supported in SOQL query. I've used Schema.getGlobalDescribe() to get all objects name. Though it returns all ...
-1
votes
1answer
130 views

Picklist related Query in salesforce

I Have a Picklist Field Like (Orderstatus__c) Field, Values are (A, B, C, D, E, F) This Picklist Field, when i am querying the Orderstatus__c Filed Those values will be displaying like Un order (B, E, ...
1
vote
3answers
3k 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) ...
2
votes
2answers
101 views

SOQL search with LIKE

I’m very confused with the soql Like operator. If I have a record with a text field that may contain: "Orders to be shipped, pack blue labels/zip/ authorization slip needed.” And a user enters “blue ...
0
votes
1answer
26 views

Bulkify Apex class for event object using dynamic soql

I'm trying to get the name of whatId and WhoId on the event object onto a string. I can do it for a single record inside a for loop, the issue I see when Im looking to bulkify the code is that events ...