Questions tagged [dynamic-soql]
Dynamic SOQL refers to the creation of a SOQL string at runtime with Apex code.
471
questions
0
votes
0
answers
40
views
Implementing autocomplete suggestion for record ids
The LWC app that I am currently working on has a feature that lets users fetch information for a record whose record ID is entered. I am looking forward to implementing a feature that proactively ...
3
votes
1
answer
213
views
Is "FOR UPDATE" available in dynamic SOQL?
The SOQL doc states that FOR UPDATE is available for inline SOQL
To lock a set of sObject records in Apex, embed the keywords FOR UPDATE after any inline SOQL statement. For example, the following ...
1
vote
1
answer
39
views
How to fetch name field for a record of given record id but known object?
I am trying to obtain all related child (look up) records of a record whose record id is passed. Salesforce docs say that for every object, regardless of type, name is a standard field, just like Id.
...
0
votes
1
answer
25
views
Database.query() question
Is it ok to use String.escapeSingleQuotes() inside of a database.query() or do you need to create a new variable using the String.escapeSingleQuotes() first and then use the new variable in the ...
0
votes
1
answer
38
views
Dynamic SOQL, LIKE and Apostrophes
I want use an Aura component to perform a lookup on Accounts. For example I want to search for an Account named O'Neills.
The query is:
query = 'SELECT Id, Name FROM Account WHERE Name LIKE :value';
...
0
votes
1
answer
32
views
How to obtain child records for a given parent record and vice versa?
I want to create an Apex function that takes a recordId of unknown entity type, identifies the entity type and subsequently returns all child records (name, id) of the given record. In addition, the ...
0
votes
1
answer
40
views
How to retrieve reference field's value dynamically
sObject record = Database.query(query); // current record values
Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
Schema.SObjectType objSchema = schemaMap.get(objName); ...
-2
votes
1
answer
46
views
Can anyone write this code in optimized way?
I know it's not the correct way to write the code like this. But can anyone help me to optimize this code without for loop?
String userName = 'test@test.com%';
List<String> objectNames = ...
0
votes
1
answer
135
views
Dyamic SOQL Query in LWC Imperative apex call not working
I am composing an LWC Component, that makes an imperative apex call to a method that takes ALL the fields of a record and return them to the client."
I am using dynamic SOQL query, that expects a ...
0
votes
1
answer
34
views
How to Create Dynamic Bound List Variable Names in a Loop for Dynamic SOQL
I'm trying to create a dynamic SOQL string based on the type of fields being used. If the field is a text area, it contains a list of comma delimited strings. For each text area field, I create a list ...
0
votes
2
answers
60
views
contact 'name' can not be filtered in a query call
I tried to run this query and got the error as 'name' can not be filtered in a query call. The query is [select id,name from contact where name like '%test%'] . The result is varying from org to org. ...
0
votes
2
answers
64
views
QueryException when using Invocable Method and SOQL
We have a flow that presents a multi-picklist on a screen that presents related Accounts.
We then want to create a related object on each of those selected Accounts.
To allow for modularity, we want ...
0
votes
1
answer
36
views
Write SOQL nested query
I have two objects. Object2 has lookup relationship to Object1. I want to write a SOQL query to fetch some data of Object1 where the territory field of Object2 is equal to UK.
Set<Id> ...
0
votes
1
answer
42
views
I am trying to use a dynamic query in an apex class to get the profiles list
select id, name, KTDO1__Candidate_Profile__r.Name
from KTDO1__Skill_Set_Experience__c
where Name ="Java" and KTDO1__SkillSet_Experience__c = "3 Yrs"
When I try to run this query, ...
0
votes
1
answer
123
views
how to replace a SOQL query with Dynamic query?
Here is the code I am trying to convert to dynamic query-
List<RecordType> jobRecordTypes = [SELECT Id, DeveloperName
FROM RecordType
...
0
votes
2
answers
169
views
How to make a date dynamic SOQL query for Database.getQueryLocator?
My goal for this class is to run for every missing day up until today, with just one call from an anon block.
I would like some assistance with creating a dynamic soql query that will work within the ...
0
votes
1
answer
80
views
Is my dynamic query correct and how do I check if its correct?
I have the query below and I need it to be Dynamic.
List<Opportunity> List = [SELECT ID,Producer__c FROM Opportunity WHERE ID IN :parameters.opportunityIds];
So I have written a dynamic query, ...
-3
votes
1
answer
63
views
Wild Card Search - Dynamic SOQL [duplicate]
I'm building dynamic SOQL based on the User Input from UI.
I'm looking to build a wild card input search.
For Example,
if user enters "Apple*", query should return all records that start ...
0
votes
0
answers
378
views
How to get all the field names and data type of each field using Dynamic SOQL with Lookups?
I am trying to get the Datatype, Label, and SObject of fields in a Dynamic SOQL Query.
For Example, I have the following objects that are called in the below SOQL Query:
"Product_User__c"
&...
0
votes
1
answer
23
views
Can I tap into the inline SOQL results with a string field value?
I am curious on how I would be able to pull out a dynamic field value from an in-line SOQL query. Is this possible? I have tried with no luck but wasn't sure if there was another way.
Decimal ...
-1
votes
1
answer
57
views
Not getting split value in dynamic soql query
Please help me how to get value for split values "valueArray[1]" in below query.
I am trying to fetch the records, but i found issue in writing dynamic query.
Please let me know if I am ...
0
votes
1
answer
54
views
Passing an array to NOT IN clause
Apex:
@AuraEnabled(cacheable=true)
public static List<Topic> getFilteredTopics(List<String> notInTypes) {
return [
SELECT Id,Type
FROM Topic
...
11
votes
2
answers
351
views
Is it possible to get a Custom Setting without the cost of a SOQL query and at the same time do it DYNAMICALLY without hardcoding the setting?
Once I had the illusion that accessing custom setting is always free and does not consume any governor limits. Until today: I've learned the hard way that this is only half-true.
It is true, that this ...
0
votes
2
answers
37
views
What is the highest performance way to work with results in a List<SOBject> returned from Database.query()?
I have a custom object called Query_Definition__c that has two fields:
SObject_Name__c (text)
SOQL_Query__c (long text)
Within Apex, the requirement is to take the record details from the ...
0
votes
2
answers
443
views
Assign dynamically values in fields via field API name
I am trying to populate a field with the value of another field dynamically based on custom metadata types.
I use the method variable.put(fieldAPIName, value) in order to populate the fields.
Here is ...
0
votes
0
answers
20
views
Test works from Dev Console. Fails in automated nightly run
My query was failing with users with a Locale other than "en_US". So I switched the date format from UTC to GMT and it works well. Unfortunately while my tests work when I run them from Dev ...
0
votes
1
answer
39
views
How to query only the labels for custom or standard objects
SELECT Fields(standard) FROM Contact
This queries all the records of all the fields in the Contact object, but I want to query only the labels of the fields so that I can create a picklist of all the ...
0
votes
1
answer
154
views
Query based on variable field name
I would like to know that how can we search based on a custom field via a variable.
For example, if I create a custom field Mobilephone for the standard object Account, then how can I search this ...
2
votes
1
answer
108
views
Is there a way to distinguish Long Text Area field or Rich Text Area field from a regular Text Area?
I need to build an interface to allow a user to filter record by the field chosen by the user. I know that I can use Text Area fields in the WHERE Clause but I can't use Long Text Area field or Rich ...
0
votes
0
answers
40
views
Is there any possibility to get dynamically child relationship names based on dynamic query/record?
Is there any way to get dynamically child relationship names from the dynamic query or even from the record(records)?
Here is an example:
String soql = `SELECT id, Custom_Field_1a__c, ...
0
votes
1
answer
157
views
Check if list of users has access to list of account records
Before Creating an accountShare record I need to check first if the user has access to the related record
I am well aware that I can get it done using the UserRecordAccess Object
select RecordId, ...
-2
votes
1
answer
268
views
Dynamic SOQL with multiple conditions and undefined amount of variables
I have SOQL like this:
[SELECT id FROM CONTACT where lastName =:lastName AND firstName = :firstName]
But what to do if there are only lastName variable? What if there are 3 variables or more?
I ...
0
votes
1
answer
757
views
Lightning datatable displaying rows but values are not visible
I am trying to display Account records through dynamic SOQL, and I am getting the queried data in the console. Also, the result screen is displaying the rows with respect to that data, but the values ...
0
votes
1
answer
1k
views
APEX Aggregate Query - Query to get Sum of Amount of all opportunities of Account when stage is Closed Won
I am having trouble making the query to get Sum of Amount of all opportunities of Account when stage is Closed Won. Please help me out. This is the Query I wrote.
Select SUM(AMOUNT) , ID , Name from ...
0
votes
0
answers
90
views
Valid SOQL that returns results does not return when run dynamically
I have an Apex class that runs a dynamic SOQL query. The logs say "Aggregations:0". However, when I copy/paste the executed query directly from the log into developer console, it returns ...
0
votes
1
answer
803
views
dynamically created query in APEX and Update the Value
Dynamically created query in APEX and Update the Value. Trying to update field value by
string objectName = 'Account';
list<sobject> recordsList;
string condition = 'id IN:' + recId;
...
0
votes
1
answer
89
views
I'm using a dynamic query to fetch records, how to treat '%' if given as input in like query to be treated as a string and not another wildcard char?
I have a LWC component which takes 4 input from the user and fetches the matching records based on the conditions in the query. In the below apex method to fetch records, the parameter 'c' which is a ...
0
votes
2
answers
198
views
lwc lookup component not returning what I search for
I found a lookup component that I am using and so far was ok until last week. The user would like to type a word and all products with that word will be displaying.
example: when a user type CPC in ...
0
votes
0
answers
32
views
Trying to query a limit of 100 orders that are broken up into multiple records based on the item
I need some assistance with creating a query that will get all the records that correspond to the first 100 orders. For example the table looks something like this:
I know I can use GROUP BY grab the ...
0
votes
1
answer
448
views
Query involving parent and child objects in where, group by and order by clause
I have an object called SRC which has account as lookup in it. SRC content will be as shown below:
SRC ID
Account__c
Status
City__c
LastModifiedOn
1
1
Yes
Delhi
12-Apr
2
1
No
Cochin
13-Apr
3
2
No
...
0
votes
1
answer
931
views
Avoid untrusted/unescaped variables in DML query error
I'm building dynamic queries in few of my apex methods. When I run the PMD code review, i'm running into the "Avoid untrusted/unescaped variables in DML query" error. Running into 3 dynamic ...
0
votes
3
answers
521
views
How to Query all fields of grand parent record with SOQL?
I have a App__c with n number of fields.
Page__c is another custom object has few fields and a field App_Id__c which is Master-Detail to App__c object.
Field__c is another custom object has fields and ...
1
vote
3
answers
1k
views
using today date in Database.getQueryLocator query String throwing errors
I am running a batch class. I am providing query in string format. I am facing issue with using a filter criteria
StartDate__c>=:System.today()
In a direct query, i could write something like
List&...
0
votes
2
answers
404
views
Second order SOQl/SOSL injection error during checkmarx scan
I am getting SOQL injection at line originalObjectQuery += ' WHERE Id = '' + originalId + '''; How can i reslove this?
public static Id close(Id originalId) {
//** Build query to return the full ...
0
votes
0
answers
64
views
Create a dynamic query for each item in for loop
Hi I want to create a dynamic query for each item in for loop , but again I don't want to execute that query in the for loop, right now since I am creating a query in for loop, I am no option but ...
1
vote
2
answers
333
views
History field is blank for this query, Please help :)
I am new to salesforce, please help me out with this one:
I am trying the following SOQL query to retrieve the changes made to the teacher object but I am getting nothing in the history tab.
I turned ...
0
votes
2
answers
380
views
Reference Set<Id> in the WHERE clause of a Dynamic SOQL in Batch class
I have a Batch class and I am trying to reference a Set in the WHERE clause of a dynamic SOQL query but I have an error:
System.QueryException: expecting a colon, found '{kA09E0000005mCySAI}'
when ...
0
votes
1
answer
174
views
What is the syntax of including not null value in dynamic soql and how to include a number variable in dynamic soql
var s = "Select Account_vod__c from Event_Speaker_AZ__c where ";
s = s + " Medical_Event_AZ__c = '" + "{!Medical_Event_vod__c.Id}" + "' "
+"...
0
votes
0
answers
513
views
Apex to return custom metadata and dynamic object data
I am looking to have a lightning web component that returns data from an object based on the record I am on that i can display on a lightning record page . I am exploring programmatically pulling a ...
0
votes
1
answer
224
views
SOQL to Pull LastLoginDate from past 2 hours but not last 30 minutes
Here is the scenario that I'm running in to. I need to able to pull users that logged in past 2 hours but not last 30 Minutes. I tried every possible way to filter this in but since we can't Use ...