Questions tagged [query]

A query is an inquiry into the database using the SELECT statement. A query is used to extract data from the database in a readable format according to the user's request.

Filter by
Sorted by
Tagged with
40
votes
3answers
17k views

Workaround for Offset 2000 limit on SOQL Query

Problem I'm trying to make a standard query pagination. I'm using SOAP API. The logic is classic: LIMIT recordsByPage OFFSET (recordsByPage*pageNumber)+1, It works fine, however, I'm facing the ...
15
votes
3answers
28k views

Filtering by Long Text Area field in SOQL

I'm working on a custom search page, which will search through the fields of the Project object. I use dynamic SOQL query similar to that: String query = 'SELECT Name, Status__c ... FROM ...
15
votes
1answer
865 views

How can adding a Subselect make a SOQL query non-selective?

I have a SOQL Query with subquery that fails to execute because it is non-selective. I don't understand why and cannot interpret the results. All I know is that tearing parent und sub query apart ...
14
votes
2answers
24k views

How is a DateTime object formatted into a String suitable for a String based SOQL query?

In order to write a where clause against a datetime field, you need to format your dateTime object into the following format: WHERE SystemModstamp > 2005-10-08T01:02:03Z How do you correctly ...
13
votes
1answer
147 views

Can Cast Child Related List to Single SObject Record - Compiler error?

This situation came up in code review and I was sure the old version should have caused a compile fail: List<Child__c> children = new List<Child__c>(); for (Parent__c parent : parents) { ...
12
votes
3answers
34k views

How to query all user with salesforce license?

I want query the list of user with salesforce license List<user> user11=[SELECT name from user limit 5000];
12
votes
1answer
513 views

Variable scope - database.query() has access to variables not in scope

I was answering a question and this little inconsistency popped up. Just wondering if anyone has come across it before, or if anyone knows why this happens. A variable that is declared within some ...
12
votes
1answer
2k views

Has anyone had issues with initial page load times when injecting a second VF page via AJAX?

I have a few visualforce pages that, together, make up a custom dashboard. The first page or "shell" page is just a HTML form that lets you select a client services rep and an optional client type ...
11
votes
4answers
597 views

QueryException: Non-selective query - Production But Not Sandbox

I am getting the following error Error:Apex trigger Lead_LTS_Update caused an unexpected exception, contact your administrator: Lead_LTS_Update: execution of AfterUpdate caused by: System....
11
votes
5answers
11k views

Can a SOQL query selecting all columns be generated at runtime?

It seems like SOQL does not have an equivalent to SQL's "SELECT * FROM ..." (If SOQL has this syntax, show me and I will mark that as the answer.) To get around this limitation, I have been using a ...
11
votes
2answers
204 views

How to combine FOR VIEW and FOR REFERENCE?

I'm writing a fluent query builder and have hit a snag. While looking at the documentation for the FOR UPDATE clause, it has this snippet: Consider using the FOR REFERENCE clause with the FOR VIEW ...
10
votes
1answer
8k views

Make SOQL Case-Insensitive?

I have this query: List<id> accounts1 = [SELECT Id, PersonContactId, PersonEmail, FirstName, LastName, net_Id__pc FROM Account where net_Id__pc = pFederationID] I need ...
10
votes
2answers
557 views

SOQL query returns inconsistent order despite ORDER BY statement

The following SOQL query is designed to return CampaignMember information by associated Contact.Name. The first time the SOQL query is run, it returns a list where two subsets of the CampaignMembers ...
9
votes
1answer
109 views

Non-Selective Query Async (fails) vs Sync (works) - Is that supposed to happen?

Running into the following issue only during async processes (i.e. Batch Apex): Code used is same for both sync and async apex. Both essentially pass a single record into the method Batch scope is 1 ...
8
votes
5answers
997 views

Why isn't a SOQL query of mine populating a list in an Apex test class?

Why does my taskOpp query below not return any records when I run this test? The query works fine in Workbench and my taskRT query works fine in both my code and in Workbench. public class ...
8
votes
2answers
2k views

How do I find merged Records?

How do I find the accounts that were merged after the merge operation? Is there any flag being set after the merge process gets completed? For instance, does any field depict that this particular ...
8
votes
1answer
7k views

Query Which Profiles Have Read Access To Specific Object?

Since I couldn't think of how to write this query off the top of my head, I thought it might be worth sharing. How can I query which Profiles have Read permission on a specific object? I knew it would ...
8
votes
1answer
1k views

ORs and ANDs in the retrieve function of Visualforce Remote Objects

Related: OR/AND condition for complex criteria with remote objects Background The retrieve query format allows the use of or and and clauses to create complex queries. The relevant documentation is ...
8
votes
2answers
632 views

For Loop by SOQL (hidden feature?) [duplicate]

After intensively using SOQL in For Loop I have found some interesting behavior which I neither can explain nor understand. Official SF documentation also does not have any notes regarding this. For ...
8
votes
2answers
2k views

Doing query as specific user

Situation: We are doing SOAP API (custom made apex webservice) calls to service using admin user. Those calls do search on Accounts (millions of records, search mostly on Name field) Account are set ...
7
votes
2answers
8k views

How do I access Custom Settings in Apex?

If I have a hierarchical custom setting: Custom_Page__c With one field: Url__c Using apex, how can I surface this field in a visualforce page? Can I just query it as if I was querying a custom ...
7
votes
2answers
9k views

Retrive globalpicklist/globalvalueset without SOQL

Is it possible to retrieve the values of a Global Picklist/GlobalValueSet using Schema class without a SOQL ?
7
votes
2answers
1k views

DateTime.Format() Documentation example causes exception

I'm trying to get a DateTime to format into a value to be used in a dynamic query. For some reason, the documentation snippet on how to format a DateTime for a query is giving me an exception. Im ...
7
votes
3answers
2k views

SOQL Multiple COUNT 's with different conditions

I have tried a bunch of different ways of getting a result about the age in only one query. I want to count the contacts that are between 20 to 29 years old and count in another column the contacts ...
7
votes
4answers
6k views

How do I SOSL across objects, matching all records with FIND clause?

To all the expert SOSL gurus lurking out there, I thought this will be an interesting one: I have some SObjects of different types and I want to return their Name values in a single query. In ...
7
votes
1answer
1k views

Apex object field for reverse lookup

Let's say I have 2 custom objects: Person and Award. Award has a lookup field to Person called Receiver. If I query an object of Award, I know I can do Award.Receiver__r to access fields of the ...
7
votes
2answers
166 views

Throwing System.QueryException on Batch Class for field “IsArchived” on Product2

We're using Schema.getGlobalDescribe().get(objectName).getDescribe().fields.getMap()to fetch all the fields in Product2 and build a dynamic query. When the string is used in database.query() method, ...
7
votes
1answer
10k views

Query all queues I am a member of

I would like to query all hardcodequeue groups I am a member of. So far it seems I can only query a queue if I hard-code it's name. There doesn't seem to be a way to query a queue and have it return ...
7
votes
2answers
3k views

Is is safer (limitwise) to call Database.getQueryLocator() with SOQL String than Static SOQL?

In my Apex Batch start() method I am returning a Query Locator to get the full 50 million records and not be limited to 50k. Is there a difference between calling ...Database.getQueryLocator('SELECT ...
7
votes
3answers
293 views

SOQL Query to retrieve Contacts from an Account sorted by the distance between the contact location and the account location

I'm trying to create a SOQL query to retrieve Contacts from Accounts, with the contacts for each account sorted by the distance between the contact location and the account location. This is what I ...
7
votes
3answers
231 views

SOQL order by distance internal server error

I am trying to add an ORDER BY statement in a SOQL query. I am already using the same statement in the WHERE clause of the query, but am getting an error saving it. An unexpected error occurred. ...
7
votes
1answer
1k views

Using In Clause with multi pick list

I'm trying to query some data in access from a multi pick-list using this query: SELECT Contact.Account.Name, Contact.LastName, Contact.FirstName, Contact.Email, Contact.Title, Contact....
7
votes
2answers
82 views

How to query an Installed Package Id

I'm trying to properly build a relative URL from within a managed package context, so that a simple link can be provided to the user to bring them to the assign licenses page specifically for that ...
7
votes
0answers
214 views

Query to move sends which contain the word “ticket” to a new tracking folder?

I just started a new job with a company and there tracking is a mess. All of the files are just at the root "My Tracking" and there are 1000s of sends. I want to move all sends with the word "Ticket" ...
6
votes
3answers
3k 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'}; ...
6
votes
2answers
8k 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 ...
6
votes
3answers
490 views

SOQL Style Guidelnes - Large SELECT Clause

I have a long SOQL query with a lot of fields in the SELECT clause and conditions in the where clause. How do you write it, so it's stylistically sound? I get that this is subjective...
6
votes
1answer
6k views

SOQL to find All Users with a Custom Permission

I was looking for a little help to find all users with a particular Custom Permission assigned to them, either via Profile or Permission Set.
6
votes
1answer
4k views

SOQL Performance With LIMIT 1 [duplicate]

I became accustomed to add a LIMIT 1 clause at the end of my SOQL request when I want to request only one record. Even when I don't declare an array as result. For example: Account account = [SELECT ...
6
votes
2answers
7k views

How to query a file uploaded as an attachment in lightning experience?

According to the release notes Lightning Experience Limitations, attachments uploaded in lightning aren't the same as attachments uploaded through salesforce classic. How can i query for the ...
6
votes
2answers
293 views

how to add lastmodifieddate in aggregate list

AggregateResult[] groupedResults; if(Schema.Account.getSObjectType().getDescribe().isAccessible()) groupedResults = [SELECT Name, FROM Account where Name like :sql or name IN:sql1 Group By Name ...
6
votes
1answer
2k views

Trying to get SymbolTable of an Apex class and get null

I'm quering Apex classes using Tooling API QueryResult queryResult = toolingConnection.query("select Id, ApiVersion, Name, NamespacePrefix, SymbolTable, Body from ApexClass where NamespacePrefix = ...
6
votes
1answer
1k views

Query based on date filtering client side

I was trying to query based on date filtering via client side ( jquery Mobile or ajax toolkit even). I want to pass the HTML input text ( in which user will enter date ) to query ( i tried converting ...
6
votes
2answers
1k views

Avoid hitting SOQL Limits but know that I was about to hit them

I want to avoid hitting the org's governor limits but at the same time I need to know if I was about to hit them. Here's what I have so far: [ SELECT convertCurrency(Price__c) FROM Object__c ...
6
votes
3answers
38k views

SOQL 'LIKE' and wildcards '%' not returning full results

I'd like to get a deeper understanding into the SOQL use of wildcards and the term 'Like'. I have the following query: SELECT name, city, state FROM Account WHERE name LIKE '%'+:searchVar+'%' Let ...
6
votes
2answers
6k views

Query Chatter Feed, Topics, and Groups

First off, my end goal is lofty and time-consuming, but we need metrics and this is the best way to do it (that I can think of). Originally, a chatter post was created on the quote, case, or where ...
6
votes
1answer
871 views

RestAPI nextRecordsURL lifetime

we are currently working on POC that queries large amounts records through RestAPI. For queries that exceed the batch query size, a nextRecordsURL gets returned. Does anyone know what the lifetime of ...
6
votes
2answers
465 views

Not all records returned in SOQL Query

I have a query that I'm using to export data: SELECT c.Id, c.SystemModstamp, ... FROM Contact c WHERE c.SystemModstamp > start AND c.SystemModstamp < end AND c.Id > string ORDER BY c.Id ASC ...
6
votes
1answer
1k views

Soql query on parents other child object

I want to write a soql query , My scenario is as follows. I have three objects objectA,objectB,objectC. objectA is the parent object for both objectB,objectC. objectA - objectB (Master-detail ...
6
votes
2answers
176 views

Creating Seed DE with Query

I'm trying to create a samples DE of records from the deployment audience, but I'm having trouble making sure all people get all possible values that the email could display. Using the code below I ...

1
2 3 4 5
27