Skip to main content
New
Stack Overflow Jobs powered by Indeed: A job site that puts thousands of tech jobs at your fingertips (U.S. only). Search jobs

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
1 answer
9k views

How to get data type of any object's field in SOQL

how to i get datatype of any filed in SOQL?
1 vote
4 answers
3k 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&...
3 votes
2 answers
2k views

How to use soql queries on multiple look up relationship object to retrieve specific data

I have 4 custom objects (as shown in the schema diagram). And they are associated using a lookup relationship. Now the objective of my question is to retrieve Product profile(product) for a given ...
1 vote
0 answers
32 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'...
1 vote
2 answers
1k views

Get Network.getLoginUrl via SOQL dynamically

I would like to get the getLoginUrl information of a Network sObject. what is the be way to get this information dynamically via SOQL? since static methods can't be invoked dynamically. Thanks
6 votes
3 answers
9k views

Concatenate fields in SOQL queries in the WHERE clause (no Apex)

I am trying to run SOQL statement in salesforce.schema tool of FORCE.COM the following query: Select c.LastName, c.FirstName From Contact c WHERE (FirstName+' '+LastName) In ('Good Name','Bad Name') ...
21 votes
5 answers
62k views

Filtering by Long Text Area field in SOQL

I'm working on a custom search page, which will search through the fields of the Project object. I use dynamic SOQL query similar to that: String query = 'SELECT Name, Status__c ... FROM ...
0 votes
1 answer
1k 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
122 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
1 answer
244 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 ...
3 votes
4 answers
9k views

Binding variables in dynamic soql

I am trying to dyanically attach a WHERE clause to a base query string by following this guide. https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dynamic_soql.htm I am ...
1 vote
2 answers
525 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 ...
0 votes
2 answers
69 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 --> <...
6 votes
3 answers
3k views

Why I can not use Map in dynamic query

Map<Id, Account> maps = new Map<Id, Account>(); for(Account acc : [Select Id from Account]) { maps.put(acc.Id, acc); } String s = 'Select Id from Account Where Id IN : maps.keySet()'...
-2 votes
1 answer
153 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
2 answers
2k 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. ...
74 votes
4 answers
29k views

Elegant way to convert Set<Id> into String for Dynamic SOQL IN comparison

When I have a Set of Id's and I want to do a dynamic SOQL query that I want to use it in for an IN comparison, I have to convert the Set to string in the format of: ('id1','id2',id3',...) The way I ...
0 votes
1 answer
60 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 vote
1 answer
940 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()....
1 vote
1 answer
4k 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 ...
-2 votes
1 answer
539 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
48 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": ...
2 votes
2 answers
850 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
1 answer
96 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='...
0 votes
1 answer
297 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
400 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
311 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
1 answer
377 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<...
-2 votes
2 answers
220 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
999 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
554 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
318 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
134 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
511 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
527 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
457 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
188 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
780 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
571 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
758 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
1k 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); ...
10 votes
2 answers
36k views

How to use the escapeSingleQuotes method?

I'm trying to use this method in a dynamic SOQL query. Follow the sample code: public static String getRowById(String sobjName, id id) { String query = 'SELECT '; Map<String, ...
-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 ...
2 votes
2 answers
3k views

How to get the Data Category in Select Dynamic Soql

I am trying to fetch Knowledge Articles based on Data Category through the below dynamic Soql query. String dynamicQuery = 'SELECT Id, Title FROM Knowledge__kav ' + ...
4 votes
1 answer
4k 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 ...
6 votes
1 answer
16k views

How to query the data that has been modified in last 30 MINUTES

we have Order__c as custom object. we are trying to extract the past 30 minutes record. where LastModifiedDate=TODAY and HOUR_IN_DAY(LastModifiedDate) > 0.5 is not working We tried SOQL : ...
0 votes
1 answer
176 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, ...

1
2 3 4 5
10