Questions tagged [dynamic-soql]
Dynamic SOQL refers to the creation of a SOQL string at runtime with Apex code.
418
questions
2
votes
2answers
85 views
Security Review - False Positive for SOQL Injection - Configuration Data (Input only by System Admin User)
I am using a dynamic query in one of our AppExchange products.
There is an LWC component within our app, which has a property called filterLogic as below:
<targetConfig targets="...
0
votes
1answer
27 views
Test data not visible by Dynamic SOQL
I have an seemingly simple aura enabled class for agreement lookup which returns maximum 8 records using dynamic SOQL. This class works fine from UI perspective. No issues so far while testing.
My ...
0
votes
1answer
22 views
unexpected token: BillingState
Im learning more about Batch Apex class and I find it pretty cool and helpful. When I remove the Where BillingSate='TX' everything works as expected. Yet when I use the Where condition I get the ...
4
votes
2answers
232 views
If I Use a Loan Pattern is Salesforce smart enough to do a SOQL for loop?
As we know, Salesforce does some magic when you do something like:
for (List<Account> accountList: [SELECT Id, Name FROM Account WHERE Name LIKE 'Acme%']) {
// do stuff
}
... such that the ...
0
votes
1answer
54 views
get count of all the fields containing data in a specific object
public static Map<String, decimal> getFieldsCount(String objectName){
Map<string,Schema.SObjectField> get_F_name=Schema.getGlobalDescribe().get(objectName).getDescribe()....
2
votes
1answer
57 views
How To use security enforcement with dynamic database.query in apex?
String objkey='Opportunity';
string recordID = '0061k000007Pyuf';
string soqlQueryCurrent='Id, Name, currency_Culture__c';
string queryStr ='SELECT '+soqlQueryCurrent+' FROM '+objkey+ ' WHERE id=:...
0
votes
1answer
46 views
How to Ignore Not Existing Field in SOQL Dynamic Query
String objkey='Opportunity';
string recordID = '0061k000007Pyuf';
string soqlQueryCurrent='Id, Name, currency_Culture__c';
string queryStr ='SELECT '+soqlQueryCurrent+' FROM '+objkey+ ' WHERE id=:...
0
votes
2answers
41 views
SOQL - ignore custom field if non existent in object
String objkey='Opportunity';
string recordID = '0061k000007Pyuf';
string soqlQueryCurrent='Id, Name, currency_Culture__c';
string queryStr ='SELECT '+soqlQueryCurrent+' FROM '+objkey+ ' WHERE id=:...
1
vote
2answers
67 views
How to remove SOQL Query from the for loop by Queueable in apex
I need to retrieve the field value given subject. But the only way I find to do it is by doing a dynamic query in a For or loop. Did anyone have a solution to avoid the query in the loop? Or any other ...
0
votes
1answer
29 views
I have got the Exception [DEBUG|Exception: System.QueryException: Only variable references are allowed in dynamic SOQL/SOSL. ] on SOQL Query
When i have executed my code i got the exception System.QueryException: Only variable references are allowed in dynamic SOQL/SOSL. . Kindly assist me.
string query3 ='select id, accountId, ...
1
vote
1answer
21 views
Dynamic query using In with a List with multiple fields
I have an array of this class
global with sharing class JiraTimeLog {
public Long worklogId;
public String jiraIssue;
public String milestone;
public String resource;
public Date ...
0
votes
1answer
52 views
Iterating over child records dynamically in apex
I have a requirement where in lightning web components , I am using design attributes so that admin can enter the objectApiname and fieldApiname.In fieldApiname,admin can give direct fieldapiname of ...
1
vote
2answers
161 views
Fetching Parent field value with dynamic SOQL
I am performing a dynamic query on case feed and fetching few fields including CaseNumber. queryResult is storing the results but it does not contain casenumber. I am able to retrieve caseNumber with ...
1
vote
1answer
136 views
get second highest salary of employee using soql
I need to calculate second highest or 4th highest salary etc.. what is the way to calculate it.
select salary__c from Staff_Details__c order by salary__c desc
I am getting the salary in desc order but ...
0
votes
1answer
98 views
Create lookup field on VF page + dynamic search based on lookup field value
I have VF page, build to perform search on Case object. I am already performing search based on Case Status, Case Number.
I want to add one more search based on field "Product". Product(...
0
votes
1answer
47 views
save button not working on pageblockTable column
I have added inlineEditSupport and save function to pageblocktable on Case object.
I want to save values in inputField "Case Review Notes" field (Case_Comments_On_VFReport__c). When I click ...
1
vote
0answers
40 views
ContentDocumentLink Limitations when querying using LinkEntityId as filter
my apologies if this has been asked somewhere else. I didn't find any answer hence I have to post this question.
USE CASE:
I am using database.query(queryString);
In queryString = 'SELECT id,...
2
votes
1answer
60 views
Dynamic csv generation for a dynamic soql query in apex
When constructing a csv via apex how do we avoid hardcoding the recordString assignment within the query loop?
Note I have a dynamic List<String> fieldsList that represent field names. For ...
-2
votes
2answers
298 views
OR condition check in dynamic SOQL query for multiple picklist value
Getting error while executing SOQL query. We have Address_Type__C is a picklist field having multiple value. We are checking for the multiple value's in the OR condition. Is the Query seems correct?? ...
0
votes
1answer
99 views
SOQL query to get the first and last day of the current month?
i need to pass SOQL query to get the first and last day of the previous month.
Example Query:
Select Name, ID
FROM Audit__C
WHERE Audit_Month__C BETWEEN 'previous month start date (2020-04-01)' AND '...
0
votes
1answer
15 views
Dynamic Soql throwing an error [duplicate]
String str = 'hellotest';
String qry = 'select id,Products__c from Account where End_Date__c > :system.today() and Start_Date__c < :system.today() and IsValid__c = true and Approved__c =' + '\'' ...
0
votes
0answers
15 views
Unable to get related data in apex when using dynamic SOQL [duplicate]
I have a requirement where I have to query certain fields dynamically based on a string that contains the fields. However, when trying to obtain the values, I get 'Invalid field' error.
A simple ...
0
votes
2answers
74 views
Soql to return results on the basis of multiple filters
I am trying to return the account records on the basis of some search keywords like AccountName, Billing Street, BillingState, BillingCity and PostalCode.
I am able to return the results but not able ...
0
votes
1answer
106 views
Unable to pass object Name in the SObject for loop to call methods Dynamically
I am trying to optimize my code, instead of using object Name in if else I want to pass the SObject parameter and combine below code
Instead of using separate objects I am trying to merge if else ...
0
votes
1answer
52 views
SOQL injection issue on source scanner report
I am getting SOQL injection vulnerability on source scanner report. Please check one of the issue below. I tried string.escapeSingleQuotes() on query string. It is helping with removing this issue in ...
0
votes
1answer
48 views
How to use a SOQL query for Sobjects like Passing Sobject as Variable inside the quey
I'm trying to write a SOQL query, But this query have to work for all object in one query. I want to use same query but I want to change object name dynamically
public class Test {
public static ...
0
votes
1answer
41 views
System.QueryException: unexpected token: accountid
I run the following code in the scheduled class:
List<String> sObjFields = DynamicSOQL.getFields('Contact');
String query2 = 'SELECT ' + sObjFields + ' FROM Contact';
...
0
votes
1answer
39 views
Relationship query not returning any records
I have a batch class, in that I'm doing a dynamic relationship query my code is as follows
global class RBS_DeleteScheduleBillRunBatch implements Database.Batchable<sObject>{
global String ...
-2
votes
1answer
74 views
How to filter records on boolean field in Batch apex
Fields are as follows:-
Assistantname which is text
Level__c is a picklist field
prestigious_contact__c is a boolean field
When I run this query I keep getting Unexpected Token :-'&&' error ...
0
votes
0answers
12 views
Dynamic Soql for Parent record metadata [duplicate]
public static List<Sobject> Soql (String ObjectName, List<String> apiNames, Set<String> IdsToQuery )
{
String query;
String SobjectApiName = objectName;
...
0
votes
1answer
50 views
How to solve this: Multiple IN condition in SOQL - System.QueryException: Only variable references are allowed in dynamic SOQL/SOSL
Hi am getting an following error while running dynamic soql. how to over come this when we use multiple IN condtion in soql query dynamically
code:
String docid = 'hi asma US6775512356';
...
1
vote
1answer
92 views
SOQL Query for all Fields on Object and filter based on certain types
I am looking to make dynamic queries, but I want to avoid compound fields in the query. Is there any way to check if the fields is a compound or overall not updateable?
public List<Sobject> ...
1
vote
1answer
45 views
Dynamic comparison of Profile id and userid fails in trigger
How do i correctly assign the userid and profileid to make a dynamic comparison. ?
// if i hardcode the owner's profileid and userid the IF gets evaluated to true, however if i dynamically compare ...
1
vote
1answer
122 views
How to query multiple object records without using soql within a for loop
I have a
Map<String, String> objectNameWithQueryString;
objectNameWithQueryString consists of 'ObjectAPIName' as the key and a 'soql query string as the value'.
My requirement is to perform ...
-2
votes
1answer
63 views
Is it possible to pass string of ids in Where IN dynamic Soql the dynamic part should accept Set id's and Lis id's [duplicate]
I have a dynamic soql in where I pass a string of ids in the WHERE IN clause this thtrows me a error:
expecting a colon, found '{'
My where clause is as follows:
WHERE Id IN {x0x0o000000000xXXX}...
1
vote
1answer
52 views
SOQL Query With Running Tally or Running Totals
I have a Payments object with dates and corresponding payments. We can query the data via SOQL in our API and the data looks like this:
SELECT Date, Amount FROM Payments WHERE CreatedDate>2019-01-...
3
votes
1answer
651 views
SOQL Query For To Get the Tabs of Particular Application
I want Soql Query for to get the tabs(Navigation Items) under one application (App) in salesforce. Suppose
Application Name is Data Management under these We have Database,Table,Column tabs as Custom ...
1
vote
1answer
69 views
SOQL Query Question?
If I have 3 parent records which each have 3 child records, and I have a list of the parent Ids off the child records so there would be 3 duplicates of 3 ids, would the SOQL for the parent object such ...
1
vote
2answers
181 views
Issue with dynamic SOQL Query
I have a following method which returns result based on the dynamic SOQL query. It was running fine until I added additional filter criteria where I am checking
Id != : ClosedCleanupId
Below is the ...
0
votes
1answer
590 views
How to pass set<id> dynamically to soql [duplicate]
I have a dynamic Soql in which I want to pass a set.
I get an error:
System.QueryException: expecting a colon, found '{'
Anonymous window
Set<Id> idSet = new Set<Id> ();
idSet.add('...
1
vote
1answer
157 views
Using LAST_N_Months:3 on CreatedDate in databaseQuery
I am setting a string qryDate = 'Last_N_Months:' + x - so it could be Last__Months:3.
I create a string qryString = 'SELECT field1 FROM Case WHERE CreatedDate=: qryDate'
and then do: result = ...
0
votes
1answer
30 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, ...
1
vote
1answer
243 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 ...
1
vote
0answers
30 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
28 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
39 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
38 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
66 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
62 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<...
-1
votes
1answer
84 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&...