Questions tagged [soql]
Salesforce Object Query Language (SOQL), modeled on SQL, for accessing information saved in the Salesforce database.
535
questions
10
votes
1
answer
2k
views
How do I bulkify queries for directly or indirectly related records?
This is a canonical question and answer developed by the community to help address common questions. If you've been directed here, or your question has been closed as a duplicate, please look through ...
15
votes
4
answers
7k
views
System.Exception: Too many SOQL queries: 101 [duplicate]
I am getting a Too many SOQL queries: 101 error on a trigger when I am trying to deploy another trigger.
I am posting the trigger which is causing the error.
trigger rollupAccountShowings on Account ...
11
votes
2
answers
4k
views
Parent and children relationships accessible via trigger?
I'm sure this has been addressed before but I can't seem to find the answer. In a trigger on a record, aside from the actual fields on the record, what do I have access to? The parent info? that ...
57
votes
6
answers
31k
views
Can report data be accessed programatically?
Is there any way to access existing reports and their data to be used in apex? Sure, I could write the SOQL manually but if I want it to mirror a specific report I would have to make code changes ...
64
votes
1
answer
24k
views
Is there a way to do Like against a list of Values?
Is there a way to mix LIKE operator with IN ?
Something Like
SELECT Id FROM Account WHERE Name LIKE IN:nameList
Where nameList is list of String?
Is this is possible ?
(I can make a dynamic query by ...
46
votes
3
answers
25k
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 ...
19
votes
2
answers
2k
views
SOQL results returning RecordTypeId which is not included in query
I am running this script from developer console.
List<Account> lstAccount = [SELECT Id, Name, BillingStreet From Account LIMIT 1];
System.debug(lstAccount);
Debug Log:
23:47:04:012 ...
73
votes
4
answers
28k
views
Elegant way to convert Set<Id> into String for Dynamic SOQL IN comparison
When I have a Set of Id's and I want to do a dynamic SOQL query that I want to use it in for an IN comparison, I have to convert the Set to string in the format of:
('id1','id2',id3',...)
The way I ...
51
votes
5
answers
19k
views
SOQL Record Locking : For Update
Well I was trying to Implement Record Locking apex but Salesforce Document doesn't seem to help much. Even tried searching stackexchange there was a old question but the answer form StackExchange and ...
47
votes
6
answers
78k
views
Howto wildcard SELECT * to query all fields of objects in APEX?
I have created sObject and I need all the fields and I have many. Is there a way I can directly get all of them rather then typing each one of them.
15
votes
3
answers
14k
views
What makes a field not groupable
I'm trying to use an aggregate query, but one of the fields I want to group by is not groupable (saw it in the soql error and then verified groupable=false in the metadata).
It's just a number field ...
16
votes
2
answers
7k
views
SOQL result ordering in the absence of an Order By clause
In the absence of an Order By clause in a SOQL query, what order will Salesforce return results in?
Clearly if ordering is important then Order By should be specified, but I recently encountered a ...
9
votes
5
answers
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 '+
...
39
votes
3
answers
52k
views
What standard and custom fields are indexed?
I'm trying to find a proper list of what standard fields are indexed by default in salesforce, as well as under what conditions custom fields are indexed.
To start things off I know fields are ...
18
votes
2
answers
25k
views
Child-to-Parent Query - [object Object] is the result
I'm trying to perform the following multilevel relationship query.
SELECT ID, SystemModstamp, Product__r.Catalog__r.Active__c
FROM Journal__c
WHERE SystemModstamp > 2013-10-02T00:00:00.000+...
8
votes
1
answer
8k
views
SOQL: Comparing two custom relationship fields in a nested query
I think I may be hitting some sort of SOQL limitation in the WHERE clause. I am trying to return fields from two parent objects, after comparing two date fields on both Objects.
The goal is to have a ...
5
votes
1
answer
7k
views
To achieve Grand total for the retrieved column in a datatable generated using Soql
I have created a VF tab in which i have retrieved the data with a SOQL statement and displayed the same with VF page using a datatable to make it as a customized report. I can't find a proper solution ...
51
votes
7
answers
48k
views
Obtaining all ContentDocument records using SOQL
According to the Salesforce documentation on ContentDocument
Users (including users with the “View All Data” permission) can only query files they have access
I find this very strange. Why would a ...
25
votes
3
answers
24k
views
Finding if which users have a record type available to them using SOQL
I would like to be able to execute a SOQL query that will allow me to see which users have access to a certain record type for a certain object.
For example, if I have a case record type called Phone ...
13
votes
1
answer
21k
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 ...
13
votes
5
answers
20k
views
SOQL aggregate query limit [Updated for Summer18]
I'm trying to use aggregate queries to save work and script statements. The object has a field for each month representing energy usage for that month for a building.
In situations where a building ...
11
votes
2
answers
2k
views
Why does 18-character ID casing matter in a SOQL WHERE clause?
When an ID value is upper-case the expected rows are returned in a SOQL query. However, when using a lower-case ID in the where clause, zero rows are returned.
It also doesn't matter if it's a ...
5
votes
3
answers
24k
views
Converting SQL to SOQL
I am transitioning to learning SOQL and am struggling with some basic concepts (specifically, joining tables and using multiple tables in the where clause). Can you help me figure out how the below ...
17
votes
4
answers
4k
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 ...
11
votes
5
answers
10k
views
How to query Deployment Details in Deployment Status? Is it even possible?
Is it possible to query deployment status->Deployment details start time and end time?
10
votes
2
answers
2k
views
Too many SOQL queries
This question has been asked before, but none of the answers on those threads have helped so far.
Getting the following error when trying to deploy a test class from the sandbox to production in the ...
10
votes
1
answer
18k
views
DML statement cannot operate on Trigger.new or Trigger.old
I have an afterInsert trigger on Events. When the Script is finished, I would like to delete the event. I keep getting this error message.
DML statement cannot operate on Trigger.new or Trigger.old
...
9
votes
3
answers
6k
views
What types of fields are groupable in a SOQL `GROUP BY` clause?
The Salesforce documentation is notably terse in describing Considerations When Using GROUP BY. The guidance provided for determining which fields can be grouped is simply:
The Field object ...
9
votes
1
answer
6k
views
Whats the Actual meaning of ALL ROWS in SOQL?
I did the following
1)Deleted a record in sfdc and then ran the query using ' ALL ROWS' keyword and i could see that as per the documentation that data from recycle bin is also retrieved with ...
7
votes
1
answer
3k
views
Salesforce query on profile not working on user language change
I have a query on profile like profilename = [Select name from profile where id=:userinfo.getUserprofileid ].name Now I have a check in VF page like profilename == 'System Administrator' . this ...
125
votes
2
answers
152k
views
Is it possible to run a SOQL Query and get a Map returned?
It is possible to run query and the results inserted into an Apex list:
List<Opportunity> opportunities = [SELECT Opportunity.OwnerId,
Opportunity....
44
votes
1
answer
132k
views
How do I build a SOQL query for records in a list of IDs?
Can some one correct my soql? I need to export records in data loader like:
WHERE Id IN ('123123123','123123fsdf')
But this following query does not work for me:
SELECT Id, Syndication_Documents__c ...
20
votes
3
answers
22k
views
Using a date for a datetime field in a SOQL Query criteria
Recently I had a strange bug in a project for a report page for closed cases. For whatever reason a case wasn't being included.
Long story short, I was querying for the cases using dates for the ...
19
votes
1
answer
45k
views
How to retrieve the file content for a ContentDocument object?
Previously, on Salesforce Classic, when a file was uploaded, it was saved on the Attachment object table. This object had the Body field.
On Lightning Experience, however, attachments are stored as ...
19
votes
3
answers
12k
views
SOQL Record Locking (FOR UPDATE)
I am looking for some more definitive and in depth information about record locking in Salesforce. I will admit I am quite a novice when it comes to the topic of record locking, and am not sure it is ...
13
votes
1
answer
3k
views
What Type of Joins are Supported in SOQL?
There used to be a really great article I could link to when I wanted to describe (or even remember) the names of various joins in SOQL, their syntax, etc. However, the link died, and I have not found ...
13
votes
4
answers
19k
views
How to query more than 50000 records in apex and bind it in vf page in jqgrid and paging?
How to query more than 50000 records (78000 records) in apex and bind it in vf page in jqgrid and implement paging in it?
I tried querying through SOQL and assigning it to list.. Am unable to query ...
10
votes
1
answer
7k
views
Didn't understand relationship
I'm getting an error - didnt understand relationship when running this query in dev console. I have set the child relationship the lookup field to IncEvents. The lookup field is on the MyRule object - ...
9
votes
1
answer
9k
views
SOQL: Bulk Fuzzy Searching
I have a list of accounts that I would like to perform a LIKE query on. Ideally, my query would be something like:
SELECT id, owner.name FROM Account WHERE name LIKE IN :entityList
Is there any way ...
6
votes
2
answers
3k
views
Can we query the info from "Data Management -> Storage Usage" through SOAP API?
Can we query the info from "Data Management -> Storage Usage" through SOAP API? If so how?
Actually, I need the count of records in all the objects in the org, and the size. (Also would like to know ...
3
votes
1
answer
5k
views
Dynamic SOQL, Access Subquery Results
I'm having trouble understanding how to access each individual result returned from a subquery. The picture shows the code which:
takes fields and objects chosen by a user and assigns them to String ...
3
votes
1
answer
972
views
How to get list of all sobject records modified today in the system?
I need a list of all sobject records that got modified today. this is not just for one object but for all objects in the system. Is there a simpler way to do this?
3
votes
1
answer
2k
views
External Id in salesforce
I have an external system that needs to update a record in my org. This system only knows the external id, but the problem is that this external id is not unique, e.g. multiple records might have the ...
3
votes
2
answers
8k
views
How do I find the child relationship name?
I'm using a SOQL to query the lookup relationships.
Primary Object: Opportunity
Secondary Object: Purchase__c.
From purchase__c we have a lookup to opportunity.
Field Name: Opportunity__c
Child ...
2
votes
1
answer
2k
views
Didn't Understand Relationship - How To Find Child Relationship Name?
I have a many-to many relationship between three objects. LGFProducts, PartsinProducts, and Parts. PartsinProducts is the junction object. I want to be able to get data like the names of the parts ...
2
votes
1
answer
5k
views
What is wrong with this query? (Unknown error parsing query)
When I run the following query in query editor I get this error.
Error
Unknown error parsing query
Query
SELECT Id, OwnerId,Account.OwnerId
FROM Contact where OwnerId = Account.OwnerId limit 100
...
1
vote
1
answer
2k
views
Event parent relationship fields are null in trigger
I am populating a junction object on from Events and want to capture info from the Event but getting the Account from Account field pulls null. Same who the name via the Who. But if I query the Event ...
0
votes
1
answer
2k
views
How to get the name of the relationship for inner queries in SOQL? [duplicate]
In Trailhead we have the query to get the Contacts for the Account named "SFDC Computing", with an inner query.
SELECT Name, (SELECT LastName FROM Contacts) FROM Account WHERE Name = 'SFDC Computing'...
30
votes
1
answer
4k
views
What formulae does the Geolocation Distance use?
Forgive me if this is a bit extremely academic in nature, but I was wondering how Salesforce goes about determining the distance between two pairs of latitude and longitude?
When I've looked at this ...
25
votes
1
answer
1k
views
SOQL bind variable scope behavior
After I posted this question, I found a similar post that seemed to answer it: Variable scope - database.query() has access to variables not in scope. I'll leave this in place for now, as I am not ...