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
2 answers
41 views

Why I'm getting "Dynamic SOQL :System.QueryException: unexpected token:SelectId" Error at the time of debugging

getting unexpected token error as in image when I debug and pass parameters to this class as below public class SearchObj { public static void searchRecord(String strObjectName,String strFieldName)...
user avatar
0 votes
1 answer
33 views

fetch field API name and field value in SOQL

I have a requirement where I have to get data using dynamic SOQL on the go. I am successfully able to form the dynamic query with fields that are provided during run time and get data as well. Once ...
  • 327
-1 votes
1 answer
37 views

How can i use custom label values in Squery- of apex class

Can anyone help me to form the dynamic query with the LIMIT value stored in custom label. Public String valueForLimit = System.Label.BuyListCustomlabelLimit; How can i use the valueForLimit in ...
  • 1
0 votes
0 answers
33 views

How to query for articles with a specific data category OR without any category?

I know you can use WITH DATA CATEGORY to query for articles in a specific data category (ex: SELECT Id, Title FROM KnowledgeArticleVersion WHERE PublishStatus='online' WITH DATA CATEGORY Geography__c ...
  • 561
0 votes
1 answer
31 views

What I'm I doing wrong in Dynamic Query

I am getting System.QueryException: Variable does not exist: recordId when running my code. The oppId is coming from a flow and the query works if I hardcode an id but not when a variable is ...
  • 111
0 votes
1 answer
60 views

How to create a dynamic SOQL based on criteriums?

I want to retrieve cases based on other objects' records I.E. I want to retrieve this case: Field : CaseNumber Operator : Equals to Value : 0123 First attempt: public static List<Case> ...
  • 79
-1 votes
1 answer
73 views

Error in Dynamic SOQL when binding a variable

I have a batch apex that contains a constructor, but when I tried to run it, I'm receiving an error saying variable does not exist fromDate, is there something I need to do to correct the query? thank ...
0 votes
0 answers
133 views

SOQL problem with redundant white space

My record has an 'Adress' string field and the value like this: 'SNBR - 772178 SNME SSTTAB, SCITY SSTATE SZIP_' Note that it has 2 whitespaces between 'SSTATE' and 'SZIP_'. However, this field when ...
0 votes
1 answer
86 views

How to use OFFSET in SOSL DYNAMIC

I need to use the offset 0 in my Dynamic SOSL, but giving me unexpected token error:- kindly help me out for the below issue CODE :- jsdhfksjfjsa;fk;alskd;lasx;;,;lms;dm;ksddmc;lsdlmc;lsdc;l;m Error :...
  • 1
0 votes
0 answers
66 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
287 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 ...
  • 64.7k
1 vote
1 answer
451 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
134 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
231 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'; ...
  • 11
0 votes
1 answer
838 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
424 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); ...
  • 25
-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
882 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
83 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 ...
  • 810
0 votes
2 answers
408 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. ...
  • 177
0 votes
2 answers
151 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 ...
  • 105
0 votes
1 answer
66 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
64 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
580 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
514 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 ...
  • 15
0 votes
1 answer
194 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, ...
  • 11
-3 votes
1 answer
127 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 ...
  • 2,168
0 votes
0 answers
1k 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
42 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 ...
  • 3,279
-1 votes
1 answer
160 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
123 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
513 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 ...
  • 33.9k
0 votes
2 answers
52 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 ...
  • 167
0 votes
2 answers
935 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 ...
  • 53
0 votes
1 answer
251 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
492 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 ...
  • 45
2 votes
1 answer
239 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 ...
  • 14.1k
0 votes
1 answer
473 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
648 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
1k 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
2k 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
201 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 ...
  • 11
0 votes
1 answer
2k 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
112 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
253 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 ...
  • 73
0 votes
0 answers
62 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 ...
  • 15
0 votes
1 answer
840 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
2k 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 ...
  • 2,168
0 votes
3 answers
667 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 ...
  • 133

1
2 3 4 5
10