Skip to main content

Questions tagged [soql]

Salesforce Object Query Language (SOQL), modeled on SQL, for accessing information saved in the Salesforce database.

Filter by
Sorted by
Tagged with
11 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 ...
user4675's user avatar
  • 233
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 ...
PartOfTheOhana's user avatar
58 votes
6 answers
32k 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 ...
Ryan Elkins's user avatar
  • 7,687
66 votes
1 answer
26k 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 ...
Avidev9's user avatar
  • 5,669
48 votes
3 answers
27k 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
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 ...
Santanu Boral's user avatar
74 votes
4 answers
29k 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 ...
pchittum's user avatar
  • 19.7k
51 votes
5 answers
20k 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 ...
Avidev9's user avatar
  • 5,669
47 votes
6 answers
82k 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.
NewBei's user avatar
  • 473
15 votes
3 answers
16k 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 ...
Shane McLaughlin's user avatar
17 votes
3 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 ...
Daniel Ballinger's user avatar
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 '+ ...
Tamil's user avatar
  • 724
39 votes
3 answers
54k 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 ...
ca_peterson's user avatar
19 votes
2 answers
26k 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+...
dannymorty's user avatar
8 votes
1 answer
9k 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 ...
ZAR's user avatar
  • 2,043
5 votes
1 answer
8k 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 ...
Mr.Blend's user avatar
  • 255
54 votes
7 answers
52k 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 ...
GuiSim's user avatar
  • 962
25 votes
3 answers
27k 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 ...
Joe's user avatar
  • 3,421
13 votes
5 answers
21k 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 ...
Shane McLaughlin's user avatar
13 votes
1 answer
23k 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
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 ...
Mark Pond's user avatar
  • 23k
10 votes
3 answers
7k 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 ...
David Reed's user avatar
  • 93.2k
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 ...
mplax's user avatar
  • 373
17 votes
4 answers
5k 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 ...
Keith C's user avatar
  • 136k
12 votes
6 answers
12k 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?
Lahari's user avatar
  • 121
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 ...
Brian's user avatar
  • 566
10 votes
1 answer
21k 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 ...
Alex Brigham's user avatar
  • 1,139
10 votes
1 answer
7k 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 ...
Mohith Shrivastava's user avatar
8 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 ...
Shebin Mathew's user avatar
126 votes
3 answers
165k 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....
dublintech's user avatar
  • 4,273
45 votes
1 answer
142k 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 ...
sfdc's user avatar
  • 13.7k
20 votes
3 answers
23k 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 ...
Ralph Callaway's user avatar
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 ...
Daniel Blackhall's user avatar
19 votes
1 answer
48k 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 ...
Renato Oliveira's user avatar
14 votes
1 answer
4k 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 ...
Adrian Larson's user avatar
  • 150k
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 ...
Sathya's user avatar
  • 3,232
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 - ...
wisemanIV's user avatar
  • 883
9 votes
1 answer
10k 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 ...
ZAR's user avatar
  • 2,043
6 votes
2 answers
4k 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 ...
Sathya's user avatar
  • 3,232
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 ...
SFDC's user avatar
  • 668
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 ...
Rock Tober's user avatar
3 votes
1 answer
1k 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?
The Beginner's user avatar
3 votes
2 answers
9k 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
3k 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 ...
user1470901's user avatar
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 ...
Masoud Az's user avatar
2 votes
2 answers
2k views

Finding sharing settings OWD

I'm trying to find the sharing settings OWD information and I have looked at the tooling/api and APEX/SOQL could not find, is that even possible to retrieve this metadata information?
Nick's user avatar
  • 7,030
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 ...
jaw999's user avatar
  • 1,317
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'...
ElHombre55's user avatar
30 votes
1 answer
5k 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 ...
Daniel Ballinger's user avatar

1
2 3 4 5
12