Questions tagged [dynamic-soql]
Dynamic SOQL refers to the creation of a SOQL string at runtime with Apex code.
494
questions
0
votes
0
answers
40
views
For the below query I'm getting System.queryexception: only variable references are allowed in dynamic SOQL/SOSL. Please find the below code for refer
global with sharing class VIA_B2B_RecordSharing_Batch implements Database.Batchable<sObject>, Database.Stateful {
private final String query;
private final String objectName;
private final ...
0
votes
1
answer
50
views
Handling Lookup Fields with Multiple Object Types in SOQL for a Custom LWC
I'm developing a Lightning Web Component (LWC) where users can select a root object and then choose fields they want to query. Some of these fields are lookup fields, which means they might need to ...
1
vote
1
answer
60
views
Best Practice - Dynamic SOQL or Static Query within if/else
I'm wondering what is the best practice in a situation where I have a conditional query - do I use an if/else to create my query string and use dynamic query in one place, or use static query and ...
0
votes
1
answer
33
views
Dynamic Soql query for a multiselect picklist
Test Data inserted:
Record1->Id = '012xxxxxxxxxxxx', Group__c = 'Assistant;Attorney;Builder Client'
Record2->Id = '012yyyyyyyyyyyy', Group__c = 'Appraiser;Builder'
String searchValue = 'Builder'...
1
vote
0
answers
39
views
Can't figure out why list aura component won't display the account name
It's meant to pull the recordId from the url of a users record page and use it to display a list of that users open opportunities. Everything is working without a hitch, except the account names aren'...
0
votes
1
answer
423
views
See what objects ContentDocument is linked to and get the count per objects
To keep it simple, I want to know to which Objects are linked my Attachments, so I executed the following SOQL query :
select count(id), Parent.type counter from Attachment
group by Parent.type
I ...
0
votes
2
answers
95
views
I am trying to fetch Account details with the text provided in lightning input lwc
I am trying to fetch the Account Name and Id while entering the text on ligtning input but I am not able to fetch the data from apex here is my code.Pleas help
<!-- mySearchListDemo.html -->
<...
1
vote
2
answers
602
views
Dynamic SOQL Error: Unexpected Token ':' - I have searched for two days, what could I be missing?
I have a batch class that will be performing some actions over selected Case records.
The only problem with this batch class is the Start method.
When the query is returned and processed, it returns ...
-2
votes
1
answer
255
views
Apex classes should escape variables merged in DML query (rule: Security-ApexSOQLInjection) - how to fix this? [duplicate]
There is one warning (mention above) in one line, please tell me how to fix?
public with sharing class VIT_CustomLookupController {
// Method to fetch lookup search result
@AuraEnabled(...
0
votes
1
answer
64
views
Issue related Dynamic SOQL query
I have written a dynamic query for filter data at run time based on the different condition.
string squery='Select id, SVMXC__Serial_Number__c, SVMXC__Serial_Number__r.Name, SVMXC__Service_Order__r....
-1
votes
1
answer
613
views
How to get data from two different object with same field if there is no relation between objects using SOQL
How to get data from tow different object with same field if there is no relation between two objects using SOQL there is one common field between two objects.
I am trying the below query :
select Id,...
0
votes
0
answers
49
views
How to modify and run SOQL query dynamically in swift/Objective-C SalesforceSDK 10.2.0?
How Update with dynamic value in the Where clause from Swift/Objective-c coding in the below
'usersyncs.json' configuration.
'''
{
"syncName": "syncDownUser",
"syncType": ...
0
votes
1
answer
111
views
Dynamic SOQL query giving error
I am trying to execute below query and getting error which says Unexpected token IN
Can someone please help to understand what is wrong here.
String str = 'SELECT Name FROM Account';
String str1='...
1
vote
1
answer
5k
views
Dynamically Pass Bind Variables to a SOQL Query With queryWithBinds Method
I was going through the new feature from Spring 23 release regarding Dynamically Pass Bind Variables to a SOQL Query With queryWithBinds Method. It seems like it is working when there is only one ...
0
votes
1
answer
351
views
How to update objects and fields without having information hard coded?
We are asking our accounts to fill out a survey with questions Q1, Q2, Q3, etc. The survey record is inserted into Salesforce, and we are building a trigger to update related records.
For example, ...
0
votes
2
answers
440
views
Dynamic SOQL Query Exception
global String taskQuery = 'SELECT Id, Subject, What.Name, CA_Created_by_name__c, Task_Record__c, Task_Dc__c, WhatId, createdDate FROM TASK WHERE WhatId != NULL AND createdDate >= :Datetime.now()....
1
vote
1
answer
502
views
Dynamic SOQL inside for loop
We have some legacy code in one of Salesforce orgs. While going through code, I encountered this piece of code
List<query_metadata__c> dyQueries=[select id,query__c,object__c from ...
-2
votes
2
answers
364
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)...
0
votes
1
answer
1k
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 ...
-1
votes
1
answer
655
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 ...
0
votes
1
answer
451
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 ...
0
votes
1
answer
145
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> ...
-2
votes
1
answer
635
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
634
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
496
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 :...
0
votes
0
answers
201
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
830
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
1k
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
647
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
872
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
2k
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 ...
1
vote
1
answer
1k
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
48
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 = '[email protected]%';
List<String> objectNames = ...
0
votes
1
answer
2k
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
330
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
3k
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
449
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
600
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
188
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
2k
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
3k
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
631
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
250
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
2k
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
121
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
440
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
438
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
...
8
votes
2
answers
1k
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
134
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
2k
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 ...