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
0
votes
1answer
21 views

Hot to get value of relationship dynamic Soql

I am using the following string in a dynamic soql: SELECT id, name, orderdate__c, status__c, sold_To_Customer__r.id, sold_To_Customer__r.name, sold_To_Customer__r.customerreference__c, ...
0
votes
1answer
37 views

Is there a simple way to get the values of a list in a comma separated string all in once

I have a custom metadata type in which I want to add the API names of some custom fields to use the values in a Dynamic Soql. I used a list to get the values of the custom metadata fields. Is there a ...
10
votes
2answers
582 views

Does the `getSObjects` method on `SObject` work with Person Account child relationships?

Our app uses a lot of dynamic SOQL, and in a client org I'm currently getting an error which I can't explain when we're performing a large query against account, including subqueries for all related ...
1
vote
0answers
27 views

getDescribe Failing on Individual Object Id in Tests (Data Protection and Privacy)

My tests of methods using dynamic SOQL queries stopped working after enabling Data Protection and Privacy. I receive the following Exception: FATAL_ERROR caused by: System.SObjectException: Field ...
1
vote
0answers
26 views

Dynamic query variable binding weird behaviour [duplicate]

I was going through something, and I stumbled upon this weird behaviour. if(true){ String var = 'GenePoint'; } Account acc = Database.query('Select ID,Name FROM Account where name=:var'); System....
1
vote
1answer
33 views

Trying to solve SOQL injection vulnerability

I have followed this official guide: SOQL Injection and came up with this: String query = 'Select FirstName, LastName, Phone, Email From Contact Where '; if(String.isNotBlank(fName)) { ...
-1
votes
2answers
35 views

get a record from obj A which is created after 3 minutes of another record in another object obj B

I am unable to form a SOQL query to get a record for below scenario. Get a record from obj A which is created after 3 minutes of another record in another object obj B. And also i want to get first ...
-3
votes
1answer
34 views

how to use like in where clause of SOQL for string

for below query like is not working static final String OrgUrl=system.URL.getSalesforceBaseUrl().toExternalForm(); string sl=[select Identity_Provider__c from Org_Url__mdt where label like:'%'+...
2
votes
1answer
46 views

Dynamic SOQL in Map with unknow sobject?

is it possible to do SOQL for the unknown object without for loop as below string theQuery = 'Select '+fiels+' From'+obj_frm +whr; Map <Id, object> oppMap = new Map<Id, object>((List<...
0
votes
0answers
14 views

How to stay within governor limits using COUNT_DISTINCT in Batch Apex Class? [duplicate]

So I have the following query that I am running through Batch Apex. I get the error: System.LimitException: Too many query rows: 50001 I am receiving this because COUNT_DISTINCT() is subject to ...
-1
votes
1answer
22 views

Dynamic SOQL Where IN Clause

Will the Where in Clause work with a list of Objects? In this case the list holds a list of IDs. Or do I need to cast this List of Objects to the ID datatype before my Dynamic SOQL. List<Object&...
3
votes
1answer
652 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 ...
3
votes
1answer
68 views

Dynamic SOQL and Object Permissions

I am hoping someone can shed some light on this for me. I am beyond confused. I have Lightning Component that has some strings to build out a dynamic query in SOQL. It is against a custom object ...
2
votes
0answers
25 views

are binding variables in dynamic soql not required to be in scope at the time of query? [duplicate]

This code works even though contactID is not in scope at the time of the query. Can anyone explain what is going on here? String query = 'SELECT Id FROM Contact WHERE '; if (true) { String ...
0
votes
1answer
54 views

compositeRequest Invalid reference specified. No value

I'm trying to execute the following compositeRequest but I'm getting the error. { "allOrNone": true, "compositeRequest": [ { "method": "GET", "url": "/services/data/v46.0/query/?...
0
votes
0answers
40 views

How to Query Knowledge Article based on Data category and Topics in Salesforce?

I have a Knowledge Article Type = AT1 and Data Category = DC1, DC2 and DC3 and Topics T1 and T2. I am trying to retrive Knowledge Article Version in apex class which contains Article Type AT1 and Data ...
0
votes
0answers
85 views

How to build the dynamic search query for multiple conditions in lightning

Hi can anyone help on this, My requirement after users selection of field, operator and value on each row on click of button it will able to call a dynamic search query with all these selected fields,...
0
votes
2answers
455 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
48 views

What's the problem with this backslash in SOQL query?

I'm receiving a String query with query params (via URL), and one is mandatory and seven are optional. So if i don't receive a param, shouldn't be included in the query. For instance: My code is: ...
2
votes
1answer
408 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
48 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
1answer
454 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
34 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
31 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
166 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
52 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
40 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
27 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 ...
0
votes
1answer
48 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
166 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
41 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
59 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
186 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
450 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
730 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
19 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
271 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
101 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
634 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
110 views

how to create dynamic query [closed]

List<Opportunity> opps = [ SELECT Id ,Name ,Amount ,CloseDate ,Stagename ,Near_to_Close_Date__c ...
0
votes
1answer
80 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
172 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
138 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 '(' ...
13
votes
3answers
25k 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
26 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
159 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
361 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)...