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
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
531 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
884 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 ...
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
159 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 ...
5
votes
2answers
909 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 ...
3
votes
2answers
1k 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
431 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
474 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
498 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
191 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
94 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
75 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
384 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
261 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. ...
1
vote
2answers
470 views

SOQL - ignore custom field if non existent

I want to run a query like this - select id from lead where inactive__c = false limit 1 If the org doesn't have the custom field inactive__c, it throws an error. Is there any way to ignore the ...
3
votes
1answer
16k views

List<id> at IN clause in Dynamic SOQl

I am fetching all the field from sObject and querying using Database.query(). When I query with List of id's it is throwing Invalid ID ('id', 'id', ...) error. for example at static soql we can query ...
8
votes
4answers
895 views

Genuine SOQL Injection issue or False Positive?

Trying to work out if this a valid issue with my code, or just a false positive I can note in report for Security Review. I have provided a slightly simplified version below. The Id I am querying for ...
-4
votes
2answers
889 views

Dynamic Search Function Test Method on QueryString

I am having a problem testing a queryString within a Dynamic Search function. For example, I have a list of strings related to Contact record. Within the VisualForce page, I run a Search Function to ...
3
votes
1answer
2k views

How to SOQL query contacts by phone number when there are more than 100,000 contacts

I am receiving a System.QueryException when searching for contacts by phone number in an APEX class: An error occurred at element myRule_1_A2 (FlowActionCall). An Apex error occurred: System....
1
vote
1answer
303 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
-1
votes
2answers
1k views

How to count active workflows in one object

Requirement:-I need to count total Active workflows for each object . Like For account object how many active workflows are there.. Is there any quick way to achieve this(query or something like this)....
3
votes
1answer
259 views

How to safely run User-generated SOQL query strings

Background Context: I'm building a small feature similar to Andrew Fawcett's Declarative Lookup Rollup Summary tool. We will allow users to enter in details for their own WHERE clauses for the ...
2
votes
3answers
703 views

Adding space in Dynamic SOQL

Can some one please to add the space before FROM in Dynamic SOQL. string query ='SELECT ' + qFields + 'FROM contact'+ ' WHERE user_num__c = \'' + String....
10
votes
2answers
2k views

Accessing child records returned from SOQL via generic SObject

I'm currently querying the records of a custom object, including some related child records. Unfortunately the parent object is unknown, so the returned results from the query is a list of SObjects. ...
-2
votes
1answer
54 views

i have records to be processed in vCommonRecords. i am not receiving the emails with expected results

My actual task is : 1.I have Account object it is having 2 child objects contacts and Orders. 2. need to process the account records with record type = Branch Integrated 3. need to send email ...
4
votes
3answers
605 views

SObject row was retrieved via SOQL without querying the requested field: Contract.Account

i'm trying to build query Dynamically for Contract object. public Contract con {get;set;} ConId=ApexPages.CurrentPage().getParameters().get('ConId'); Map<String,Schema.SObjectType> ...
3
votes
1answer
1k views

SOQL Dynamic Query building using Map.get(List)

I have a doubt. Suppose I want to query on Account object filtering based on a given list of IDs. Below snippet works fine when I have a list of Ids. List<String> accountIds = new List<...
3
votes
1answer
642 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
1answer
1k views

Select Count() with dynamic SOQL - how to stay in Governor Limits?

I am trying to fix my code so I don't hit any governor limits on my SOQL queries. Long story short: I am just learning on how to use maps, but I'm trying to figure out how I can do a SelectCount ...
-1
votes
1answer
90 views

How to update the custom field using soql with limit?

I have to update Description__c field in Account object where BusinessUnit__c having BU1 to BU1000. I have the records BusinessUnit__c field contains BU1 to BU2000. I need to update Description field ...
0
votes
1answer
950 views

no viable alternative at character '\' dynamic soql issue

I have below method which gets called from page by supplying the search keywords: public PageReference runIntermediariesSearch() { soql = intermediariesSoql + ' where Name != null '; if (...
2
votes
1answer
3k views

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

how to i get datatype of any filed in SOQL?
5
votes
2answers
7k views

isDeleted=True is not working in SOQL query

Wondering why this query will retrieve ZERO records when executed in Workbench and Developer console. (Though i have records in Recycle Bin) Select Id, IsDeleted FROM Account WHERE IsDeleted = TRUE ...
7
votes
2answers
2k views

BillingAddress in query generate error

I have a query like below in an Apex Class in Sandbox. query = 'SELECT Id, Name, BillingAddress, BillingLatitude, BillingLongitude FROM Account WHERE Name = \''+ name +'\' AND '; query += '...
0
votes
1answer
2k views

Dynamic SOQL for getting all objects in Salesforce Org

I am creating a VF page which contains a Picklist of all objects in my Salesforce org including Custom Objects. I am getting an error 'unexpected token: 'null' when I select custom object. VF Page ...
2
votes
1answer
185 views

Showing matching keyword sentences from SOSL/SOQL results

We have a requirement to search in large text area field (for e.g. Description). We are using SOSL for the same. While showing results on the VF page we want to only few sentence from Description ...
0
votes
1answer
322 views

Custom field visibility error on managed package installation

I have a managed base package and an extension package. The base package had a remote site as one of the components but I had to remove it. Since I couldn't remove the remote site from a released ...
1
vote
1answer
210 views

Transfer SelectOption Values to Dynamin Query

Trying to get the values to my Controller that I can change the limit on the displayed List on my Page. I'm Using a dynamic query and everything is working fine but what's below. What am I'm missing? ...
2
votes
1answer
1k views

How to search for text in Rich Text area field in Apex

i want to search a text in Rich Text area field of a custom object. Since We can't use the RichTextArea field in the where clause of SOQL, I am looking for the way to search a text. Is there any way ...
0
votes
2answers
430 views

query as string type in controller class

Can any one explain me...what is the meaning of below lines. I get it from This link. String qryString = '<strong class="ph b">SELECT Id, title, UrlName, LastPublishedDate,LastModifiedById FROM ...
0
votes
1answer
1k views

Pass parameters from URL to SOQL query.

How can i pass parameters from URL to Controller? I want to pass URL parameters to My controller class where i can query to fetch data with the help of these parameters.
-1
votes
3answers
175 views

Trailing 12 Months Formula

All, **EDIT: Sorry for being too vague. I'm trying to add another field to my sales summary that displays on Account pages. I'm trying to grab the trades that fall within a date range of the past 12 ...
-1
votes
1answer
324 views

Count on sObject

EDIT: What I'm asking is, do I have to execute two separate query one for retrieving the information and one for count? is that possible to put both together in one query? in the .NET you just have ...
1
vote
2answers
228 views

common field between account table and contact table

I have Three questions 1.) Can you please let me know how to write a SOQL query to get the contact based on a specific record 2.)What is common column name between acount and contact table 3.)How ...
1
vote
1answer
664 views

I am getting Error “ Variable does not exist: queryResult”

Please Find the code <apex:page controller="SOQLController" > <apex:form> <apex:outputText value="Enter Name" /> <apex:inputText value="{!name}" /> ...
3
votes
1answer
164 views

custom setting SOQL vs methods

i often come across scenarios where we have some custom setting with lots of fields created which has rows for multiple purposes. So for a specific scenario, it is often needed to filter all the rows ...
9
votes
5answers
2k views

What's wrong with this SOQL

Declared a string and assigned SOQL value as shown below. While running I am getting an error. String country = 'United States'; String accountQuery = 'SELECT Id,BillingPostalCode,County_Name__c '+ ...
2
votes
1answer
2k views

How to filter query for specific types of parent lookup?

for (SObject deletedObject : [SELECT Id, isDeleted, LastModifiedDate, parentId FROM Attachment WHERE isDeleted = true AND LastModifiedDate >= :timestamp ALL ROWS]) { It appeared, that recently ...