Questions tagged [dynamic-soql]

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

1
vote
1answer
195 views

DataBase.Query: System.LimitException: Too many SOQL queries: 101

I am trying to use Aggregate result and dynamic query. I have tried the below code and I did get 101 error. Please help me in optimizing this code to avoid hitting governor limits. The error is at ...
1
vote
3answers
1k views

no viable alternative at character '%' in dynamic soql

I am creating this dynamic query and I am getting this error String qry = '[Select id, name From selectedObject Where selectedField LIKE : '%' + userInput + '%' ]';
4
votes
3answers
232 views

Salesforce Relational Query

I have 3 Objects ObjectA__c, ObjectB__c, ObjectC__c. ObjectA__c looks up to ObjectB__c ObjectB__c looks up to ObjectC__c ObjectA__c and ObjectC__c are not related directly. How do I access the ...
2
votes
3answers
528 views

SOQL query problem in Batch

I'm trying to form a query in SOQL. In scheduler .. sch.accountdList = AccList; sch.query = 'SELECT id from Account where ID IN :'; Database.executeBatch(sch,200); and in Batch start.. ...
1
vote
1answer
379 views

Invalid field error when querying a parent record's field

This is my SOQL query List<BOG_Committee_w_Membership__c> bogQueryList = [ SELECT BOG_Committee__r.Name, BOG_Committee__r.Official_1__r.Name, BOG_Committee__r....
3
votes
1answer
240 views

Does Dynamic SOQL Support Bind Expressions?

I want to show a table of items, when a user clicks on the header of the column, it will sort the items by ASC/DESC. Based on my internet searches, I need to use dynamic SOQL to include variables ...
0
votes
2answers
992 views

how to escape wild character _ underscore in LIKE SOQL Clause

I have this query Select Id, Email, ContactId, Username from User where Username Like '\_%' works perfectly with Devloper console and give me users whose username starts with _ I am using this code ...
2
votes
2answers
150 views

batch class is failing due to time while processing SOQL due to timeout error

Hi batch class is failing due to time while processing SOQL in start method due to timeout error the query is: query= 'Select id from customObject__c where deal_Expires_On__c < = today and ...
4
votes
1answer
5k 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
1answer
509 views

How to get all email type field values

How to get all email type field values in a salesforce lead record from a record id in apex class.
3
votes
1answer
325 views

SObjectType name conflict in queries

I'm creating lookup fields on an object dynamically using the Metadata API, saving the name of a field as a Custom Setting and building queries dynamically. This works perfectly, but there is a ...
3
votes
1answer
83 views

How do I return a dynamically casted list?

So I have the below code which I created that dynamically creates and runs a query, and stores it within a type casted List. But I cannot figure out how to get it to work with the initial declaration '...
0
votes
1answer
6k views

Dynamic SOQL :System.QueryException: unexpected token: <

I am getting the error: DEBUG|Query : Select Id from TestObj__c where CreatedDate <= 2016-07-29 00:00:00 |EXCEPTION_THROWN|[33]|System.QueryException: unexpected token: < |FATAL_ERROR|...
0
votes
1answer
173 views

Dynamic soql : unexpected token: <

I am getting the above error for : for(String objName : objAPINames){ for(sObject s : Database.Query('Select Id from ' + objName + 'where CreatedDate <= ' + reqDate)){ recordIds.add((...
3
votes
2answers
1k views

How to find parent records with only 1 child record

I want to pull all the parent records which have only 1 child record either using a query or report or any other way. For example all the accounts with only 1 contact record. I don't want to create ...
0
votes
1answer
414 views

Database.Query() method casting issue

I am trying to re-word this code in a custom controller: public Double getFebruary() { Double amountX = (Double)[SELECT SUM(Amount)amt FROM Opportunity WHERE RecordTypeId =:oppNBRecordTypeId AND ...
15
votes
4answers
1k views

How to find out if an Object is a collection or single value?

I have some dynamic SOQL code in which I'd like to identify whether a method argument is a collection or a single value: SObject[] query(SObjectType sobType, String field, Object data) { // Want ...
2
votes
1answer
57 views

Query on parent child related objects in Salesforce

There are 2 objects Account & Address and their relationship is master detail. In address there is a checkbox called primary and most of the accounts will have 1 address which is marked as ...
3
votes
1answer
3k views

no viable alternative at character '\'

When I run the below code, I get this error: no viable alternative at character '\' Code: public void getChildRecords() { DescribeSObjectResult describe = objectVar.getSObjectType()....
0
votes
1answer
675 views

SOQL add dummy column [duplicate]

Is it possible to create dummy column while fetching in SOQL Like select 'Dummy Column Text' as DUMMYCOL from MY_TABLE
2
votes
2answers
221 views

SOQL Query: Stored XSS Error

I have given my code for Security code Scanner but it is given the following error due to Query: Stored XSS My query is like this. loan=Database.query('SELECT Name, fintechLLC__Application__c, '+ ...
3
votes
2answers
431 views

Dynamic SOQL - issues in managed package

1) When Querying namespace_X__object1__c like so: namespace_X__object1__c sm = Database.Query('Select Id, Name, Security_Description__c, product_type__c from namespace_X__object1__c where id=:...
0
votes
1answer
139 views

Facing problem for a Group by multiselect picklist

I have a multiselect picklist called status with 3 values and 5 amount fields..The problem that i am facing is that whatever value i select from status,My code is grouping by for all 3 values. For e....
0
votes
1answer
205 views

Need guidance for using Group by clause in apex class

I am newbie so for the first time i am using group by clause.But i am not getting where i am going wrong. I have a VF Page where there is a status field which is a multi-picklist and a record type ...
1
vote
1answer
145 views

how to specify dynamic query field values to custom setting fields?

I have a dynamic query which has the where condition like this: ' WHERE (Contract_State__c=\''+'Complete Activated'+'\''+'OR Contract_State__c=\''+'Partially Terminated'+'\''+')'+' AND ...
0
votes
1answer
362 views

Using variable in Query

Can I use variables for objects in my SOQL query? I have the variable like: public sObject objectvar; Which gets a record of type Account. How can I use this variable in my SOQL query like: Select ...
0
votes
1answer
41 views

List Result is null

StaticResource sr = [select body from StaticResource Where Name = 'kalpak']; String contents = sr.body.toString(); LIST<String> alOne =new LIST<String>(); List<String> arrrrr = ...
2
votes
1answer
4k views

SOQL Dynamic Query on objects ( Dynamic sobject name in soql )

String str = 'Order'; List<SObject> listData = [Select Id From str ]; Can we query like this, I want to query dynamically
3
votes
1answer
709 views

Dynamic Visualforce page not showing Checkbox values correct after page reload

I have the following Visual force page: <apex:form id="mainForm" > <apex:actionFunction name="renderConsolePage" action="{!renderConsolePage}" rerender="out1"/> <apex:...
0
votes
2answers
597 views

Retrieving Dynamic SOQL results. Runtime error - “Invalid field Owner.Name for…”

I had a question in regards to dynamically retrieving the results of Dynamic SOQL that I have set up in my controller. I want to be able to access fields on the Lead object (Lead.Name) itself as well ...
0
votes
1answer
37 views

Getting compile error while creating dynamic SOQL

queryStr+ = 'AND Sales_Order__r.sales_year__c =' +\'' +:strYear+\''; This is my string.strYear is the year value which i want to add dynamicaly. I am getting an error "Compile Error: unexpected ...
1
vote
1answer
810 views

How to Format the numbers entered in the Input Text Fields

When i try to search with 1000000 and 1500000 in Price Min and Max fields.the soql query is executing fine.but when i enter the values seperated with commas like SFmin=10,00,000 and SFmax=15,00,000....
1
vote
1answer
44 views

A brief about Dynamic SOQL concept

can you give a complete manual/page for referring Dynamic SOQL where as https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dynamic_soql.htm never providing considerable ...
6
votes
3answers
1k 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()'...
0
votes
1answer
3k views

Dynamic Query String Where clause concatenation

I am newbie & trying to create a dynamic querystring on the basis of some conditions, & even when it does not satisfies any condition, the query should be able to run properly with where ...
2
votes
3answers
494 views

Upsert failed in apex

I'm trying to do upsert and I get duplicate error on Unique field. Shouldn't upsert take care of whether to update an existing record or to add a new record? Error: caused by: System.DmlException: ...
6
votes
1answer
797 views

Undelete error: entity is deleted

I'm trying to undelete records using apex and it is throwing me an error: entity is deleted List<MyObject__c> undeleteObj = [select id, Unique_Id__c from MyObject__c where ...
2
votes
2answers
2k 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
0answers
43 views

Get the number of Opportunities for each User in the org (the count must include the records to which the User has atleast read access)

I need to get the count of Opportunity record for every User in the org where the User has atleast read access on the Opportunity record. I need to store the data obtained per User for every month in ...
4
votes
1answer
150 views

Dynamically using Field

I have a function as below: public PageReference resendEmails() { List<ts2__Placement__c> selectedPlacements = new List<ts2__Placement__c>(); List<Timecards__c> timecards = new ...
4
votes
2answers
739 views

Semi Join on String

I have a junction object called Trip_meeting__c to connect Event to Business_trips__c. Because you can't create a lookup to Event, I am using a text field Meeting__c to hold the Event Id and will ...
2
votes
2answers
937 views

create a map with keys = fields names and values = query result

I am trying to create a map from a result of a SOQL query, this map contains the name of the fields as keys and the values of the query as values for example: List accounts = [SELECT Name, Email ...
1
vote
1answer
354 views

Using multiple variable with same name in dynamic SOQL

Good day everyone I have some problem in regards with using dynamic query with too many variables. To explain further below is some part of my code. String QueryString = ''; List<List<String>...
0
votes
2answers
446 views

How to get the records using dynamic soql for the date field which is equal to NULL

I have a requirement where the user should be able to include the records where the due date is not populated when i uncheck the checkbox field in the vf page.In my case that date field is named as ...
0
votes
1answer
452 views

How to get the records for null value in the picklist field using dynamic soql

I have a picklist field Executed__c with None,Yes,No values in it.The query which i have written is fetching the records when the user selects yes or No.But when user selects None,null value is ...
3
votes
2answers
190 views

Query non existing custom object

I'm on a developer org on which I have a managed package that I manually install on customers orgs. Each customer's org is a bit different, with different requests/requirements. The code is as ...
0
votes
1answer
92 views

SOQL not working

I have a dynamic SOQL query where in I am using order by clause.I want to sort it by product Style SOQL soql = 'select id, name,Warehouse__c,Product_Reference__r.gii__ProductStyle__r.name, ...
0
votes
2answers
72 views

Dynamic SOQL error

I am getting the following error while running my dynamic query.But when i make it normal query it works.Error is : Didn't understand relationship 'gii__Product__r' in field path. If you are ...
1
vote
1answer
300 views

Call dynamic SOQL from other method in apex

Good Day everyone, I have a problem in regards with calling a method that contain a dynamic SOQL. To explain further, below is a sample code: public class commonFunction { public static String ...
1
vote
1answer
225 views

How to find a value in all column of an object?

How to find field_name/api_name name for any object that contains a value? I'm working on a object that has dozens of fields but I'm after finding out particular value belongs to which field name. ...