Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [dynamic-soql]

Dynamic SOQL refers to the creation of a SOQL string at runtime with Apex code.

4
votes
2answers
131 views

Can Apex SOQL query variable binding be done in a method other than the method which invokes Database.query?

Apex Commons has some brilliant solutions, but one of the things which I feel is missing is an object-oriented approach to the SOQL query's "WHERE" conditions. I'm presently working on my own ...
1
vote
0answers
95 views

What deep magic exists in Apex and can we replicate it? [closed]

When reading Apex code, there are at least two instances where SFDC is doing something more than the is immediately apparent given the syntax of the code, both of which somehow relate to SOQL: SOQL-...
0
votes
1answer
66 views

Display dynamic calculated field names in Visual Force page [closed]

I have an object as objDates with field names as Day1__c, Day2__c and so on till Day366__c. I'm using DayOfYear() to access the field values dynamically. I'm able to read(get) and write (put) values ...
0
votes
0answers
63 views

Get nested relationships dynamically in Apex

I am building a dynamic SOQL from a JSON file. As of now, I am able to build SOQL for direct parent and direct child objects dynamically. However, I am stuck at a complex/deep relationship. E.g. ...
-2
votes
1answer
38 views

Assign row values from one object to another object as columns or fields

I have row values as dates in one object, i.e dates within a given year. I have a second object with field names as Day1__c, Day2__c and so on till Day366__c. I want to assign the dates to the fields ...
0
votes
1answer
145 views

AccountContactRelation SOQL returning null with dynamic filter values

I am trying to fetch AccountContactRelation recordsrelated to specific accountId from Lightning component via server side call. I am passing the AccountId as a param to the apex controller. But ...
1
vote
1answer
392 views

Dynamic Field References in Lightning Component

I recently posted a question regarding a component I am building. That post has the code I will be referencing. I have been able to make the necessary edits and now I return an sObject to the ...
0
votes
3answers
127 views

How to print dynamic SOQL at run time?

I have a collection of set and and i am doing dynamic binding at run time. Set<String> accountset=new Set<String>{'a','b'}; I am executing query like List< account>=[select ...
2
votes
1answer
336 views

Is LIKE Against a List Not Supported in Dynamic SOQL?

I'm trying to use LIKE in my dynamic SOQL with a list. My code: SELECT Id, Name FROM Account WHERE Name LIKE ('%somevalue%', '%testvalue%') I can't and I don't want to use variable reference for ...
0
votes
2answers
167 views

Using Apex, how can we can we query all the fields and CreatedDate for Account or any other Standard Object?

I need to run the below query for 200 fields changing the field each time and then copy the resulting most recent date.Is there any way to do this quicker than doing it 1 by 1? SELECT name, ...
0
votes
2answers
145 views

Is there a way to make dynamic apex field references bind a reference to the fields?

Is there a way to make dynamic apex field references bind a reference to the fields? To illustrate the question, let's take the following example query: String query = "SELECT myField__c FROM Account"...
2
votes
1answer
117 views

Invalid bind expression type of ANY for column of type Decimal

I know this question has been answered in few places my scenario is a bit different I think. I'm building a dynamic SOQL query, the WHERE clause is going to be dynamic. I have a List<String> ...
4
votes
1answer
520 views

Using single quote by curly braces in String.format in Dynamic SOQL

I'm struggling to use String.format to replace a token with a value when the token is within single quotes: Example: String query = String.format('SELECT Id FROM Availability WHERE Person__c = \'{0}\...
1
vote
1answer
17 views

Scheduler Class error

I am writing a Scheduler Class to send out mass Emails(HTML email template) based on the time I schedule, below is my code global class pS implements Database.batchable<sObject> , Database....
0
votes
2answers
147 views

APEX SOQL retrieve values dynamically based on string variable

In my apex code i have a variable resultField and a List<Id> objIds. What i need is a List<My_Obj__c> objs = [select Id, :resultField from My_Obj__c where Id in :objIds];. This is not ...
10
votes
1answer
500 views

Does the `getSObjects` method on `SObject` work with Person Account child relationships?

Our app uses a lot of dynamic SOQL, and in a client org I'm currently getting an error which I can't explain when we're performing a large query against account, including subqueries for all related ...
1
vote
1answer
139 views

Invalid bind expression type of String for column of type Decimal. Auto type casting?

I ran into this exception while trying to make some dynamic SOQL queries(also SOSL but haven't gotten to test those yet). Basically I'm trying to build a query string and add a dynamic value as one ...
0
votes
1answer
248 views

Dynamic SOQL Query Exception: : unexpected token: '&lt;EOF&gt;'

I am receiving the following error when running a test on my code. However, it seems to run fine in the debug line above it, so I'm confused regarding the source of the error: System.QueryException:...
0
votes
1answer
337 views

Dynamic soql picklist binding in WHERE clause

I have an auraenabled method in my lightning controller apex class. My requirement is that when user selects a picklist value of status__c and/or mode_of_travel__c as a filter and click on apply then ...
0
votes
2answers
23 views

I have 1M records -some records are from data loader and there is no picklist restriction

I have 1M records -some records are from data loader and there is no picklist restriction I want to see uniuqe values for account object with that perticular values.
2
votes
1answer
367 views

Database.Query Variable Does Not Exist

How can I get the field results from a dynamic database query to be available to be put into a list? Here is the code I have: //Query on the destinationObjectFieldName results List<sObject> ...
1
vote
0answers
62 views

Fetch records from child relationship using Apex [duplicate]

I have a remote action that need to fetch an object child relationship data, but the catch is that is has to be dynamic. For example, the remote action will get Case, CaseComments, list of fields in ...
0
votes
3answers
1k views

how to pass picklist value in Dynamic SOQL

I am using dynamic soql where I am reading the conditions from an XML and getting those as a String but I am not able to find it who the query will structure String query = 'SELECT id, Name FROM ...
1
vote
1answer
74 views

Dynamic soql reference JigsawCompanyId field

In dynamic Soql  when I try to query JigsawCompanyId , it queries null.name for ParentID I queried parent.name, like wise for JigsawCompanyId how should i query SELECT Name,AccountNumber,ParentId,...
2
votes
2answers
372 views

Dynamic soql query passing null ID value

Using a dynamic soql query in my managed package , In my where condition am passing id value, string whereCond = NameSpace('fldName') +' = \'' +keyType+ '\'' +' and ' + NameSpace('fldName') +' = \'' +...
0
votes
1answer
62 views

How to display all accounts once the contact login as Community user?

From the below code i can get the all Accounts linked to that contact(community user).but here the problem is i'm using the email id as static how can i make this dynamic.once the community user login ...
1
vote
2answers
2k views

Custom Metadata type variable for SOQL In Clause

I query a custom metadata type value and try to use it in IN clause. Scenario 1: Works! Custom Metadata value has AccountHandlerTest ( not in single quotes). ACustomMetaDatatype__mdt custMeta =[...
0
votes
1answer
75 views

SOQL equivalent of PATINDEX()

Trying hard to find an equivalent for the below SQL. Any help/suggestion PATINDEX('%[0-9,c][0-9,p,a][][A-Z,0-9][A-Z,0-9][A-Z,0-9][][1-9,A-Z][0-9,A-Z][0-9][0-9][0-9]%', FIELDNAME) > 0
2
votes
2answers
508 views

Workaround for SELECT * (SELECT all) in sfdx force:data:tree:export SOQL

In certain parts of our existing Apex code base, we've used dynamic soql in combination with object describe methods as a workaround to achieve the equivalent of SELECT * that's normally available in ...
9
votes
0answers
82 views

Is there a work around to allow binding of variables in the sfdx force:data:tree:export query file

When using sfdx force:data:tree export with an in-line query, you can bind variables by creating them in the cli before running the export command, like so: CURRENTYR=2017 sfdx force:data:tree:export ...
0
votes
1answer
53 views

Filtering results of an SOQL query

I have a SOQL query with a lot of filters and I want to group the results and process objects which match a certain filter. For eg. I could have a query where I want to process different kind of leads ...
0
votes
2answers
658 views

Field is inaccessible in this context

We have a managed package app which makes dynamic queries where the customer can set which fields to query on an object. The customer has enabled in her org the service called 'Field Service ...
0
votes
1answer
327 views

How to combine the two soql queries as a single SOQL query?

how to combine the two soql queries as asingle query? Contact con = [Select Id,Name,AccountId From Contact Where ContactId In (Select ContactId From User Where Id=:UserInfo.getUserId()]; List<...
1
vote
2answers
673 views

System.IndexOutOfRangeException: Index was outside the bounds of the array

I am trying to fetch all the attachments for a record from salesforce by .Net webservice. Below is the code which i am trying to do. If i am fetching a single attachment, i am not facing any issue. ...
2
votes
0answers
347 views

How to dynamically query in Remote Object Model?

See my code comments in my controller for what I'm trying to do. This article might help as well: Overriding Default Remote Objects Operations Page <apex:page> <apex:remoteObjects &...
3
votes
1answer
1k views

Dynamic SOQL, Access Subquery Results

I'm having trouble understanding how to access each individual result returned from a subquery. The picture shows the code which: takes fields and objects chosen by a user and assigns them to String ...
-1
votes
2answers
2k views

Dynamic query using like operator

What's wrong in this query? It's throwing below error message Compile Error: Found punction symbol or operator '%' that isn't valid in Apex String QueryString= 'SELECT id,FirstName,LastName,...
2
votes
1answer
182 views

Group by part of string in SOQL

Is there any way to Group By part of string in SOQL. For example something like: Select Id, Name from Object__c group by Name.substringBetween('.','.') So query by part of a string field and not ...
3
votes
2answers
135 views

How to keep soql out of loop, and still be functional

I have this Schedulable Class that finds all Email Campaigns of a certain age and sends that age to an external service. I am pretty sure I am doing it wrong. First I want to pull the values for the ...
0
votes
1answer
73 views

Setting Dynamic Query Criteria Based On a Variable

I need to define a clause for my dynamic SOQL query, based on the value in my userRegion variable, by adapting the query from this answer. When I try to use String queueOwnerRegionClause = ( ...
1
vote
1answer
400 views

Phone numbers to search irrespective of the format stored in Database

I have the requirement where I need to search a phone number in the UI like => 8405678978. So if I am passing the number in the UI like this 8405678978, it is not querying from the database as in the ...
1
vote
1answer
219 views

query the accont records based on distance

public String distance=50; String units='mi'; //lat,lon has latitude and longitude values List <Account> Addd =database.Query('Select Name,Phone,BillingLatitude,BillingLongitude from Account ...
0
votes
1answer
152 views

Need help in dynamic soql Formation

I have a requirement where in dynamic query i have to change the format of a string.Below is the way i have tried i am getting following error after adding getTempStringFormatValue method in the below ...
1
vote
1answer
841 views

Want to fetch the child relationship name from the Lookup field name?

I am developing a functionality where I am to check for the presence of Child records, before executing a part of code. I can't do hardcoding since my code is going to be a part of a managed package, ...
0
votes
2answers
74 views

Created a dynamic string and want to fetch list size on the basis of that string [duplicate]

I have an object that is having multiple child objects. I want to perform certain actions only if the current record has child records associated with it. For this I am checking the related list's ...
1
vote
2answers
2k views

An unexpected error occurred. Please include this ErrorId if you contact support: 76743200-1017657 (1358022652)

Using the below code, I get this error message: An unexpected error occurred. Please include this ErrorId if you contact support: 76743200-1017657 (1358022652) String sql = 'SELECT Id, ...
2
votes
3answers
349 views

Building dynamic query AND/OR

My question is continuation from here This is the sample SOQL query which I'm trying to build dynamically and I have dozens of fields, it has AND OR My question is: I'm trying to figure out how to ...
0
votes
3answers
4k views

Building dynamic query string where 'AND' clause concatenation

EDIT: One thing I forgot to mentioned is that, there is a condition what fields to be added to WHERE clause for an example: Match1 = the where clause should be `emp_name__c, emp_num, emp_code` Match2 ...
1
vote
2answers
304 views

build dynamic SOQL condition

How to build the above query condition dynamically (i.e.) if same field label like "email" should be in OR conditions remaining labels should in AND condition eg... where [((email=:'test@gmail.com')...
1
vote
1answer
91 views

Create Dynamic Table On the basis Of 2 Objects [closed]

There are 2 objects one obj1 and obj2 I have to create dynamic table in visualforce page in which if new record is inserted to the obj1 then one row should be added to table and if one record in obj2 ...