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
2
votes
2answers
53 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
28 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
28 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
31 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
37 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
21 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
28 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
39 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
57 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
51 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
29 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()....
0
votes
0answers
13 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
134 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
30 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
26 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
235 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
210 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<...
0
votes
1answer
56 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
86 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
47 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
50 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
86 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
31 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
58 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
132 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
330 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
295 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
245 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
56 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
53 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,...
3
votes
1answer
97 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
499 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
153 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
16 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
16 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
95 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
215 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
64 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
56 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
51 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
50 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
103 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
1answer
63 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
437 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
53 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
223 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
73 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
61 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
902 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
71 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
2 3 4 5
9