The Stack Overflow podcast is back! Listen to an interview with our new CEO.

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
0
votes
1answer
368 views

Variable does not exist: portalUserInfo.conAccount.Id in Query

Please help with this error: String query = 'SELECT Project__c,' + ' Project__r.Testing_Submitted__c,' + ' Project__r.Project_Sub_Phase__c,' + ' Project__r....
2
votes
3answers
3k views

Dynamic SOQL query

I'm trying to build a dynamic query but I think I may have the wrong syntax. String query = 'SELECT ProjectId__c from Project__c' projectList = Database.query(query + ' WHERE Name__c equals 'pp2'); ...
0
votes
3answers
176 views

Dynamic Field Query error from non sys admin users: unexpected token: 'from': ()

I am trying to clone a record and dynamically query all fields. This works fine for system administrator but something is going wrong for non system administrator users trying to trigger the logic. ...
3
votes
1answer
353 views

SObject row was retrieved via SOQL without querying- Using Dynamic References

I am referring to a code from salesforce documentation https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_dynamic_vf_sample_standard.htm where it is shown how to build a list ...
2
votes
3answers
840 views

Using a variable after FROM in SOQL statement

I am building a custom VF component where I have an attribute which of type Object. I use this attribute to query first 10 records and display it using pageblocktable. The user can provide any object ...
0
votes
1answer
40 views

How can I query email field by comparing the date field?

I want the emails from contact where due_date__c is less than 15 days and 1 day. Select id, email from user where Contact.AccountId in (select Location__c from Grant_Schedule__c where ...
0
votes
1answer
43 views

label value inside another label

There is a label label_query which contains the SOQL query say 'Select name from Account where recordtypeId = 'value coming from another label'. In another label is stored recordtypeid. Now to use ...
2
votes
2answers
2k views

Dynamic Query - System.QueryException: expecting a colon, found '.'

Suppose I have one code, HI, which is mapped to these values: HIRT, HIFS,HISL,HIST,HIGC,HIAN,HIIS,HICV,HISR,HOLI. When I select HI those values are are passed into a dynamic soql query. For a small ...
0
votes
1answer
620 views

Convert lead failure- Cannot update converted lead?

Line: 128, Column: 1 System.DmlException: ConvertLead failed. First exception on row 70; first error: CANNOT_UPDATE_CONVERTED_LEAD, cannot reference converted lead: [] Got above Error from Below ...
2
votes
2answers
326 views

Using wildcards for column names in dynamic soql in apex

I have a scenario where my columns names can be of form genesis__prod__c/docgen__prod__c/lnd__prod__c,etc depending upon which package is using my solution package. Here genesis, docgen and lnd are ...
0
votes
1answer
378 views

Creating a dynamic SOQL query using a MAP referencing different sObjects?

So I have the below code: Map<Id, String> sMap = new Map<Id, String>(); for(CKSW_BASE__Service__c s : Trigger.new) { if(s.VS_Site_Survey__c != null) sMap.put(s.VS_Site_Survey__c, '...
0
votes
3answers
68 views

dynamicSoql query

public class query { public string accname{set;get;} public string accindustry{set;get;} public list<account>account{set;get;} public void result() { account=[...
1
vote
1answer
211 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
236 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
594 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
456 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
266 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
1k 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
6k 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
578 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
345 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
85 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
7k 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
208 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
2k 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
470 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
2k 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
58 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
4k 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
806 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
237 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
440 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
157 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
216 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
172 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
435 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
720 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
645 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
839 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
45 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
4k 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
522 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
860 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
3k 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 ...