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
2answers
26 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
0answers
19 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
1answer
30 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
1answer
26 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
1answer
32 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
0answers
24 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
1answer
88 views

Dynamic field mapping in apex

I'm very new to Salesforce. I'm quite stuck on dynamic field mapping. I have got a use-case, where I have inserted field names with the respective id in custom metadata. Id Field id-123 ...
0
votes
1answer
39 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
1answer
45 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
1answer
107 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
1answer
201 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
0answers
36 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
1answer
101 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
1answer
34 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
2answers
84 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
0answers
23 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
1answer
70 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
1answer
305 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
3answers
222 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
3answers
407 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
2answers
183 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
0answers
41 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
2answers
94 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
2answers
105 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
1answer
52 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
0answers
317 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
0answers
49 views

Transforming a read-only map<String,Object> criteria of a RemoteObjectController.retrieve into workable Apex SOQL?

How can a visualforce page (or the page's controller) access the NON-paginated results size of a Remote Object Model's RemoteController.retrieve query? Here is the relevant part of my override method,...
0
votes
1answer
30 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 ...
0
votes
2answers
78 views

SOQL query for more than one field to exclude null values

I have around 12 fields. Trying to write a SOQL query for more than one field to exclude null values. For single field which is not null, I am able to get the records. I want to a SOQL to get the ...
1
vote
1answer
110 views

Database.Query does not return fields with null value - Reasking

This was asked previously here however the answer isnt useful. Using an invocable class with a dynamic database query. If any of the fields in the query return a null value then the field is dropped ...
1
vote
1answer
200 views

Dynamic Queries on Dynamic Objects at Volume

We are trying to create a mechanism that would process user dynamically created queries and create "Contributors" for each matching record. The object model is as follows: Account -< PO ...
0
votes
1answer
54 views

Try to solve a dynamic SOQL query [closed]

String lvQueryUp = 'SELECT Id, StartDate__c, Name FROM CustomObject__c WHERE'; for(String lvindex : myIndexListName) { lvQueryUp += ' ( Name = '; lvQueryUp += '\'' + lvIndex + '\''; ...
0
votes
1answer
34 views

Select all fields in a custom object dynamically in a specific order

I have a custom object that I need to select all fields from in a specific order to create a text file in a specific format. So far, I've been dynamically accessing all the fields I need via .getMap()....
1
vote
0answers
66 views

Is that possible to use query plan for dynamic SOQL queries?

I know we can verify straightforward SOQL in query plan. Now, I am trying to find a way to use query planner for a dynamic SOQL queries. My SOQL query depends on several Ids (list of Ids) and binding ...
4
votes
2answers
175 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
42 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
44 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
237 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 ...
-2
votes
1answer
251 views

How can i convert apex method into batch?

public void addVisibilite() { Map<Id, List<Id>> accountContactRelationIdsMap = new Map<Id, List<Id>>(); for (AccountContactRelation accountContactRelation : (List<...
1
vote
1answer
63 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
2answers
202 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
50 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
65 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
132 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
100 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
126 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
523 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
632 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
660 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
798 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(...

1
2 3 4 5
9