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
1
vote
1answer
111 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
509 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
69 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
91 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
3
votes
2answers
660 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
101 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
67 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
1k 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 ...
1
vote
2answers
491 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
839 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
410 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
2k 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
3k 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
230 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
137 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
80 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
525 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
369 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
216 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
1k 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
94 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
455 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
6k 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
401 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
122 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 ...
0
votes
1answer
116 views

unexpected token found -null in dynamic query when i ran my test class

class method:- Error on this line lstofSobj = Database.query(query); -Unexpected token null public void deleteRecord(){ //system.debug('typeName::::'+typeName); ...
1
vote
3answers
5k views

System.QueryException: expecting a colon, found 'setids'

I keep getting the error: System.QueryException: expecting a colon, found 'setids' Why do I get this error? How can I fix it? public Database.QueryLocator start(Database.BatchableContext context) ...
-1
votes
1answer
450 views

Warning when using fflib_QueryFactory

When performing a sub query, I get the following message: WARN|fflib_QueryFactory.subselectQuery(Schema.SObjectType) is deprecated and will be removed in a future release. Use fflib_QueryFactory....
5
votes
2answers
327 views

Record Not Returned in Query in Managed Package

I think I'm going to have to find someone internal for this one, but posting to see if anyone has any ideas about this at all. The Problem We've got code in a managed package that's querying for ...
0
votes
1answer
899 views

soql query on case

I actually need a soql query to fetch those case records in which the incoming emails from email to case are more than one in the related list of case. One criteria is that the subject of the email ...
1
vote
1answer
3k views

Escape Sequence Single Quotes Error

I am creating a dynamic query. string s = '%' + searchText + '%'; string query = 'Select name, ShippingCity, ShippingState, ShippingCountry, rating, type, Industry, ownerId From Account Where name ...
1
vote
2answers
574 views

unexpected token: IN in dynamic soql

I have written a code which will give my dynamic soql and using this soql my execution will work. But i am getting this erro unexpected token: IN41 Below is my code Code public class ...
0
votes
3answers
196 views

Dynamic query Help?

I have created a custom Setting as "ContactSetting" and one field as "Agents_Field_Name" So my custom setting is like: Name:FirstName Agents_Field_Name:FirstName I am trying to query Contact record ...
1
vote
1answer
38 views

Capturing the Lead deletion log using dynamic apex

I am trying to create an entry in the deletion_log__c object before the lead record gets deleted. I would like to capture all the lead field names along with values in the deletion_log__c object with ...
0
votes
1answer
157 views

Risks of replacing SOQL query with QueryLocator [duplicate]

I used to have this block of code in a widely used method: SObject[] ls = Database.query(q); SObject[] children = new SObject[]{}; for (SObject l : ls) { for (SObject c : l.getSObjects('...
3
votes
2answers
477 views

Inconsistency with error “Aggregate query has too many rows for direct assignment”

I have a Box__c record with 100 Doors__r, 104 Motors__r, and 0 Wheels__r. ISSUE #1 I am getting the error System.QueryException: Aggregate query has too many rows for direct assignment, use FOR ...
0
votes
1answer
81 views

save error :unknown property 'DataInsert.fields'

Here is my apex class: global class DataInsert { // property declarations Set<String> fields ; global PageReference doInsert() { // other logic ...
0
votes
3answers
72 views

How to separate the required fields from Custom Object record?

I'm posting this question previously but i'm not achieving my goal for that i posting again I have a custom object called Incident__c. and it has some fields Imtpact__c Incident_state__c ...
1
vote
2answers
283 views

Query if Lead not modified in the current month?

Is there a way to query if a Lead has not been modified in the current month by using LastModifiedDate?
-2
votes
2answers
898 views

How to search a custom object using one or more input pick list fields from a VF page and display the result(s) in a pageBlockTable

accept the input as strings (in an extension), build & execute the query, populate a list element, display the list. Please give an example.
4
votes
2answers
2k views

Dynamic query in a for loop

I need to retrieve the CreatedDate of the last record creates of every custom object. But the only way I find to do it is by doing a dynamic query in a For or loop. But I’m, of course, limited to 100 ...
2
votes
2answers
1k views

Variable text string for SObject get method?

I want to use a variable string rather than a hard-coded string in my get method. For example, for every Field in Object A there will be a record in Object B and the record name is the field api name ...
4
votes
1answer
440 views

Is IN operator equivalent to Equal operator in SOQL when binding a list variable?

While testing some SOQL queries I noticed that the Equal operator behaves like the IN operator when using a list bind variable All the queries below run without any error and return the same result ...
6
votes
3answers
2k views

Possible to use bind :variable inside SELECT clause?

I cannot use the String[] ss inside the SELECT statement. It is giving me errors: unexpected token: ':' Code public void getSubscribers(Id listId){ String[] ss = new String[]{'Id', 'Name'}; ...
1
vote
1answer
658 views

Unexpected token '(' error batch apex

global Database.QueryLocator start(Database.BatchableContext BC) { String query = 'select id,ParticipantName__c,EpisodePoPEndDate__c from BPCIAe__c where id in :CHildParentMap.keyset() OR id in :...
25
votes
1answer
611 views

SOQL bind variable scope behavior

After I posted this question, I found a similar post that seemed to answer it: Variable scope - database.query() has access to variables not in scope. I'll leave this in place for now, as I am not ...
4
votes
2answers
2k views

Bind a List variable in a Dynamic SOQL Query

Code 1 List<String> accNameList = new List<String>{'Acc1','Acc2','Acc3'}; List<Account> accountList = Database.query('SELECT Id FROM Account WHERE Name IN:accNameList'); Code 2 ...
0
votes
0answers
37 views

“System.LimitException: Too many SOQL queries: 101”

I have SOQL on 17 objects to delete sharing Need help since we cant use SOSL on _share__c objects list<Lease__Share> deleteLeaseShare = new list<Lease__Share>([select id from Lease__Share ...