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
47 votes
3 answers
26k 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 ...
Martin Borthiry's user avatar
21 votes
5 answers
60k 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 ...
Hleb's user avatar
  • 397
16 votes
1 answer
22k 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.
Austin Russell's user avatar
16 votes
1 answer
2k 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 ...
Robert Sösemann's user avatar
15 votes
2 answers
27k 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 ...
edgartheunready's user avatar
13 votes
6 answers
67k 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];
Teja's user avatar
  • 1,412
13 votes
1 answer
22k 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 ...
Adrian Larson's user avatar
  • 150k
13 votes
1 answer
156 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) { ...
Adrian Larson's user avatar
  • 150k
12 votes
1 answer
760 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 ...
Nick C's user avatar
  • 6,553
12 votes
2 answers
386 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 ...
Adrian Larson's user avatar
  • 150k
12 votes
1 answer
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 ...
AJ D's user avatar
  • 183
11 votes
2 answers
21k views

Retrieve globalpicklist/globalvalueset without SOQL

Is it possible to retrieve the values of a Global Picklist/GlobalValueSet using Schema class without a SOQL ?
HSG's user avatar
  • 997
11 votes
1 answer
17k 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 ...
Jose's user avatar
  • 383
11 votes
4 answers
1k 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....
Laxman's user avatar
  • 243
11 votes
5 answers
13k 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 ...
edgartheunready's user avatar
11 votes
2 answers
2k 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 ...
Tehn-r's user avatar
  • 146
11 votes
2 answers
1k 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 ...
salesforce-hacker's user avatar
10 votes
4 answers
11k 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 ...
Matt and Neil's user avatar
10 votes
1 answer
7k views

SOQL query to fetch records with reserved characters ('*', '/', '(', ')')

Hoping there is a simple answer that I am overlooking. Currently, we are able to search for the following reserved characters with an escape sequence, eg a backslash character '\', in SOSL: & | ! ...
Evelyn Grizzle's user avatar
10 votes
1 answer
191 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 ...
Eric's user avatar
  • 54.1k
9 votes
2 answers
3k 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 ...
battery.cord's user avatar
  • 8,815
9 votes
2 answers
2k 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 ...
Brian Miller's user avatar
  • 5,162
9 votes
2 answers
6k 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 ...
Łukasz Skrodzki's user avatar
8 votes
5 answers
1k 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 ...
Rob Alexander's user avatar
8 votes
2 answers
10k 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 ...
Daft's user avatar
  • 2,661
8 votes
2 answers
17k views

Didn't understand relationship in FROM part of query call [duplicate]

I am trying to query the child record using the parent record id. I understand that we have to use the child relation name in the inner query to get the child records. select id, (select id from ...
SfdcBat's user avatar
  • 4,781
8 votes
2 answers
6k 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 ...
Priyalakshmi's user avatar
  • 1,456
8 votes
3 answers
19k views

SOQL Count distinct occurrences in column

I have to pull data from a Salesforce database and get a count of the number of times each category appears. Currently, I have it pulling a list of the categories and then I use a perl script to ...
Ryan McClure's user avatar
8 votes
1 answer
14k 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 ...
Thomas Riddler's user avatar
8 votes
1 answer
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 ...
Charles Koppelman's user avatar
8 votes
0 answers
290 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" ...
Stan Alachniewicz's user avatar
7 votes
3 answers
43k views

StartsWith in Select Query

In a test class I inserted a product record in the testSetup and another one in the method. When I query the product I need to filter to get to the one record I want to assert against. The solution in ...
Dan Wooding's user avatar
  • 3,498
7 votes
2 answers
13k views

Get all contacts and leads from campaign members

I can't think how to write a query to return all the contacts and all the leads (IDs, Names, and Phones) from CampaignMember. I've never used much else rather than the standard [SELECT field FROM ...
Adam 's user avatar
  • 1,426
7 votes
3 answers
3k 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 ...
Aldo Escutia's user avatar
7 votes
1 answer
617 views

Possible bug in SOQL LIMIT clause

I've just encountered a weird behaviour of SOQL and I wonder if it's a bug or maybe some feature I do not understand: looks like the compiler lets you add an incorrect LIMIT clause - LIMIT1 for ...
Bartosz Śliwiński's user avatar
7 votes
1 answer
2k 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 ...
Domas Poliakas's user avatar
7 votes
2 answers
17k 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 ...
Gusk's user avatar
  • 260
7 votes
1 answer
9k 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 ...
Martin Lezer's user avatar
  • 7,295
7 votes
2 answers
275 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, ...
jema's user avatar
  • 423
7 votes
2 answers
4k 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 ...
Robert Sösemann's user avatar
7 votes
1 answer
1k views

SOQL bug for null required-lookup fields?

It appears that querying null values for required lookup fields always returns 0 results, even if some records have no value in the required field (e.g. records created before the field was made ...
Brent Bowers's user avatar
  • 3,094
7 votes
1 answer
2k views

DX CLI force:data:tree:export Query returned no results

Records are returned when I execute this sfdx force:data:soql:query -u Dev --json --query "SELECT Id, Name, (SELECT Id, Name, AccountId FROM Contacts) FROM Account WHERE Id IN ('0010z00001T1uXSAAZ','...
SF1Dev's user avatar
  • 775
7 votes
2 answers
4k views

Entity 'Task' is not supported for semi join inner selects

I want add a default task to an opportunity when this one is close won and the opportunity hasn't any task. I get the error compiling the below code: Entity 'Task' is not supported for semi join ...
Van Busse's user avatar
7 votes
2 answers
15k 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 ...
Grant's user avatar
  • 320
7 votes
3 answers
626 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 ...
KB145's user avatar
  • 866
7 votes
2 answers
3k views

SOSL query returns only 250 records even if there are more than 2000+ records present

I have two queries List<sobject> soslRecords1 = Search.query('FIND {I need help res*} in all fields returning Incident__c (id) where ID IN:rec_ids')[0]; List<sobject> ...
Shilpa's user avatar
  • 71
7 votes
3 answers
405 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. ...
TemporaryFix's user avatar
  • 2,937
7 votes
1 answer
7k views

SOQL: No response from the server error

I have below query to run either in workbench or Developer console, query editor. While on workbench, I get error: UNKNOWN ERROR: Error Fetching http headers and in Developer console error as No ...
Testing_SFDC's user avatar
  • 2,940
7 votes
1 answer
2k 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....
Charley Mills's user avatar
7 votes
1 answer
786 views

Query to UserRecordAccess for multiple record ids returns unpredictable results

I am using the query editor. Consider the following query: SELECT RecordId, HasDeleteAccess FROM UserRecordAccess WHERE UserId = '005J0000006QnWhIAK' AND RecordId IN ('00UJ000000AZUulMAH','...
shillem's user avatar
  • 432

1
2 3 4 5
34