Questions tagged [soql]

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

879 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
10 votes
1 answer
140 views

Why the Sorting Logic in Salesforce SOQL and UI is VERY different from other Systems?

The ordering mechanisms in Salesforce are really odd. Take any SObject having any Text field (e.g. Name on Account) and create some Records. Do that on an Org with no other Records of the type (e.g. a ...
Uwe Heim's user avatar
  • 34.1k
10 votes
2 answers
885 views

Field filter does not Work for Text Formula field used in SOQL

I have a simple SOQL query on Account which has a field Full_Address__c which is joint of Billing Street, City Zip. When I use this field as a filter it doesn't return the records: Example: String ...
Ashwani's user avatar
  • 22.4k
8 votes
1 answer
213 views

Query highest value of custom Field on Large Object

Existing Logic: We have a trigger that gets the highest value of a custom Field "UIN__c" on various Objects and increments the value by 1 on each new Record. This Field functions as an ID ...
César Antonio Villalta's user avatar
8 votes
0 answers
3k views

getRecordTypeInfosByDeveloperName doesn't work with duplicate Developer names

Our product comes with a couple objects including RecordTypes. In our customer org I'm adding some RecordTypes and experienced, that I can give them names that the packaged types already have. So now ...
itsmebasti's user avatar
  • 6,280
7 votes
0 answers
212 views

APEX Schema ChildRelationships: why have some relationships their relationshipName = null?

There is some strangeness in the some standard Childrelationships. Most Relationships are as expected, but let us take Account and Quote as an example: On Quote we have a standard lookup field Quote....
Uwe Heim's user avatar
  • 34.1k
7 votes
1 answer
645 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
6 votes
0 answers
223 views

Contact MiddleName interferes with FirstName functions in full and partial sandboxes

We have Middle Name enabled in production. In a full sandbox, when we try any standard workflow, Flow Get Records step or SOQL query that involves Contact.FirstName = 'some value', the query/function ...
David Cheng's user avatar
  • 6,870
6 votes
0 answers
323 views

SOQL Aggregate functions circumventing limits?

We're working in a managed package that leverages SOQL aggregate functions and we want to ensure we are considering governor limits appropriately. To prepare for it we have created a Scratch Org with ...
jonathanwiesel's user avatar
6 votes
2 answers
1k views

SOQL with ORDER BY and NULLS LAST ASC return wrong order results when we order by field from relationship

I noticed that SOQL with ORDER BY and NULLS LAST ASC returns results in wrong order (especially when I order by field from relationship). I wonder if it is some kind of bug or I've done some mistake ...
Grzegorz Połuch's user avatar
6 votes
1 answer
729 views

Unable to query with cross-Object pick-list field filter on Custom Metadata SOQL

I came across something weird, SOQL which has a filter as cross-Object picklist field doesn't return rows, even if records exist. Minimum viable code to replicate: Create a new custom metadata type, ...
Pranay Jaiswal's user avatar
6 votes
0 answers
3k views

Why does SOQl query for Owner.UserRole.Name on Opportunity cause error in Opportunity Territory Assignment apex class

I've been working on an Apex class to do our Opportunity territory assignments based on the example here. I needed to modify it to support our rules that included checking the User Role on the ...
Jonathan Miller's user avatar
6 votes
0 answers
206 views

What's happening upon deletion of a Group record

I just ran a few consecutive tests of inserting and deleting a bunch of groups via the developer console (execute anonymous). Inserted 50 Group records: List <Group> groups = new List <...
Boris Bachovski's user avatar
5 votes
0 answers
93 views

Error when using FIELDS(STANDARD) in an Apex SOQL query : System.QueryException: No such column 'EffectiveDate' on entity 'Quote'

I recently implemented the new FIELDS(STANDARD) functionality in Apex queries and I am using the following query now: SELECT FIELDS(STANDARD), Custom1__c, ... , CustomN__c FROM Quote WHERE Id =: ...
Jacob Barazoto's user avatar
5 votes
1 answer
186 views

Discrepancies between downloaded Setup Audit Trail and SetupAuditTrail query

I have noticed that delegated user logins (i.e. when a managed package admin logs in via grant login access) show up in the downloaded setup audit trail, but do not show up in a SOQL query of the ...
SFDC Neuf's user avatar
  • 1,487
5 votes
0 answers
86 views

Using Salesforce indexes

I'm working on an org that will have around 25m opportunities when data migration is complete. I'm trying to anticipate the issues we will face running batch processes against this data volume. We ...
sefg's user avatar
  • 51
5 votes
0 answers
500 views

Working with Very Large SOQL Queries

Background This is a question about your experiences managing huge amount of data for UIs. With an ERD like this, where the arrow directions reflect the fields lookup directions. (e.g. entity "B" ...
Lucas Buyo's user avatar
5 votes
1 answer
500 views

SOQL error with relationship

I have one query as below: select id,functional_system_user__c, Test_Created_Date__c, Test_Login_Date__c,lastmodifieddate,name, isactive,Reactivation_Date__c,email,...
Jack vardy's user avatar
4 votes
0 answers
435 views

System.UnexpectedException: common.exception.SfdcSqlException: ERROR: portal "C_6031" does not exist

Since the Summer 22' release these uncatchable UnexpectedException errors have been popping up sporadically on code that hasn't changed in multiple orgs we manage. The stacktraces always originate ...
Gobius Dolhain's user avatar
4 votes
0 answers
63 views

ContentVersion queries omitting recent records unless queried by an ID field

We are seeing a very strange behavior in a Summer '21 sandbox. Queries for ContentVersion will not return "recently" created records, unless queried by an ID or relationship. For example: ...
Jason Clark's user avatar
  • 11.4k
4 votes
2 answers
403 views

How to replicate the functionality of delivered "File Engagement" lwc card?

In our org we have a need to programmatically replicate the functionality of delivered “File Engagement” component/card. Here is a snapshot from our live org, on a ContentDocument view page: Since ...
kivanconer's user avatar
4 votes
0 answers
74 views

Is this a good Model for "Guaranteeing" Record Updates Don't Fail due to ROW_LOCK/Race Conditions?

Background: The zqu__Quote__c object in our org has two child objects from another managed package we use for eSignature and credit card capture. One of those two child objects collects the Credit ...
Morgan Marchese's user avatar
4 votes
1 answer
364 views

Find distinct accounts and fetch their respective record ids?

I'm trying to fetch person account records that are unique and I'm trying an aggregate query as such: SELECT count(Id), FirstName, LastName, PersonEmail FROM Account WHERE IsPersonAccount = true ...
erikvm's user avatar
  • 701
4 votes
0 answers
166 views

SOQL query: "sObject type 'FeedPollChoice' is not supported" for specific user

I have an application that is making calls against the REST /services/data/<api version>/query/ endpoint. My Salesforce org has two users: Alice has the "System Administrator" profile, and Bob ...
DavidProctor's user avatar
4 votes
0 answers
53 views

Should I be concerned about thousands of write operations per minute?

I am setting up a POC which would create a junction between User and Case (using Lookup relationships only). We would have 10k+ users each touching several records per hour, so we might expect this ...
Adrian Larson's user avatar
  • 148k
4 votes
0 answers
86 views

SOQL query results differ on selecting from varying columns

I'm querying on Contact object where the results are varying on Bulk API vs querying on developer console. Total records on Contact is 997820. Query on developer console: select count(id) from ...
dmachop's user avatar
  • 1,089
4 votes
0 answers
602 views

Deleted contact's ID is not removed from converted lead. Why?

We have a requirement to delete all converted leads whose corresponding contacts have been deleted. Upon implementation we noticed something odd: After creating and converting a lead via UI (classic ...
Christoph's user avatar
  • 992
4 votes
0 answers
154 views

Salesforce big objects pagination

Given that SOQL for big objects doesn't support OFFSET, how should pagination be implemented for big objects?
ploc's user avatar
  • 315
4 votes
0 answers
1k views

USING SCOPE Everything not working

I wrote a trigger on ContentDocumentlink to get a count of number of files uploaded against Service_Request__c (Custom Object) record.It works fine for new files are uploaded on Service Request record....
sfdc's user avatar
  • 13.5k
4 votes
1 answer
2k views

Easiest way to delete a million records?

Been doing tests in sandbox in which I've created about a million accountshares that I need to get rid of for testing. I'm trying data loader in bulk api mode to export than delete but I keep ...
J. Zhang's user avatar
  • 313
4 votes
0 answers
113 views

Is This Project Possible?

I'm setting up a Wordpress site for a new customer. They have moved their customer database from a plesk environment to a salesforce database, 13 records per row including address, id, phone number, ...
Many Hats Digital's user avatar
4 votes
0 answers
142 views

Trigger Design Question

A bit of context: Our company sells vacation rentals and has over 60 properties. When a customer chooses a property, it is stored in a look-up field called Lead.Property__c. They will also choose ...
Alex Brigham's user avatar
  • 1,119
4 votes
0 answers
2k views

how to read all Content Notes saved as 'SNote' (Beta New Notes feature) for a Parent record all users?

I have been trying to read all New Notes (richtext version) via SOQL query in Apex Controller class. The design specifications for new notes signifies that they are stored in as ContentVersion ...
VarunC's user avatar
  • 5,768
4 votes
0 answers
610 views

Query Opportunity Partner Name

I am trying to write a SOQL query that pulls info from opportunities, and I need to pull out the name of the primary partner accout(if there is one). This isn't for a trigger, but for a nightly data ...
michael's user avatar
  • 41
4 votes
1 answer
2k views

Is there a simple way to generate a create table script from a salesforce class?

I am looking for a way to synchronize Salesforce data with a local database. At the moment I just want a pain free way of downloading the data. I've been playing around with importing CSVs from the ...
JonM's user avatar
  • 141
4 votes
0 answers
458 views

Loading Tasks using REST API returns no result, but second try returns a page of Tasks

Sometimes I experience weird issue when loading Tasks over REST API using simple SELECT Id, ... FROM Task SOQL query take quite some time and then returns with nothing, but on the second try it ...
antonlitvinenko's user avatar
4 votes
1 answer
183 views

Subqueries in soql for loop vs standard soql queries

I have 26 accounts and 24 contact records in the org and running a SOQL query on them (fetching Accounts along with contacts). Found that if SOQL for loop is used then the child records fetched in the ...
user1228's user avatar
  • 303
4 votes
2 answers
102 views

System.NullPointerException: Attempt to de-reference a null object Error

Method : This just one method of the class I am testing from Dev console public Employee__c getEmployeeDetails() { Employee__c emp = null; emp = [SELECT field1__c, field2__c, field3__c FROM ...
SFDCRookie's user avatar
4 votes
1 answer
98 views

SOQL not returning row (when it should be)

Running into a very weird issue that is actually causing preventing my IDE from compiling (mavensmate)... When Mavensmate compiles, it first checks the server version of the file to make sure it can ...
NSjonas's user avatar
  • 9,887
3 votes
1 answer
73 views

Is the User Mode approach to object and field security acceptable in a security review?

This Enforce User Mode for Database Operations looks by far the cleanest approach to implement the object and field-level security that is required to pass a Salesforce AppExchange Security Review. (...
Keith C's user avatar
  • 134k
3 votes
1 answer
102 views

Why does this query exclude records if the field order is changed

I have code that works on a scratch org but isn't working in production. I've tracked it down to a query that's searching a table. The Apex code looks like this: SELECT Id FROM Tag__c WHERE Name IN :...
Chuck's user avatar
  • 815
3 votes
0 answers
243 views

ContentDocumentLink SOQL doesn't return all rows

I have the same question as this one (but couldn't comment on it) To reproduce the issue: Map<Id, Contract> limitedContracts = new Map<Id, Contract>([ SELECT Id FROM Contract ...
Peter Yao's user avatar
3 votes
0 answers
92 views

Why is my Salesforce-SOQL-Subquery-Query discarding entrie

UPDATE It seems that this issue only occures if the for-each-loop handles more than one entry. If the SELECT-Statement just handles one Near_By_Metadata__mdt, everything works fine and i get all ...
reggi's user avatar
  • 66
3 votes
0 answers
520 views

Reliable Salesforce JDBC to be used with DataGrip

Do you recommend any particular JDBC for Salesforce (can be paid) which is reliable enough to be used for commercial purposes along with DataGrip (or similar) software? I've been checking similar ...
Pawel Gumiela's user avatar
3 votes
0 answers
355 views

SOQL query in Trigger returns no results but returns a row in Developer Console

I have the following code snippet in a Helper class that's being called by an After Insert trigger (modified to demonstrate my objective): Set<Id> reuseIds = new Set<Id>(); reuseIds.add('...
mchandler's user avatar
  • 131
3 votes
0 answers
30 views

Any way to re-enable first time login screen?

Doing some automation testing, and wondering if there is any way to re-enable the screen that shows up the first time a user logs into a sandbox asking you to register your phone number or click 'I ...
trebleCode's user avatar
3 votes
1 answer
205 views

selectivity threshold + OR condition in where clause

I'm facing trouble in understanding salesforce documentation, about selectivity threshold if SOQL uses two fields in where clause with 'OR' Condition. For e.g. Select id from account where FieldA = ...
curious_techy's user avatar
3 votes
0 answers
80 views

Strange SOQL Query result

So i used two queries one after another in same org: Q1: SELECT Id,Name, Project__c, Activity__c, AMS_Solutions_c__c FROM Design_Time_Sheet__c WHERE Project__c = null OR Activity__c = null ORDER BY ...
Marcin Trofiniak's user avatar
3 votes
1 answer
570 views

Cannot ORDER BY when querying Custom Metadata

I have Custom Metadata types with simple relationships between them. When I query them with a relationship query and try to ORDER BY, only 1 of the inner records is returned. I run this in Anonymous ...
iwhitt567's user avatar
  • 440
3 votes
0 answers
936 views

SOQL "All Rows" on Bulk API alternative

I am required to retrieve all the records (including archived and deleted records) from a Salesforce object. I understand that this can be achieved using queryAll(). However, I have an environment ...
dmachop's user avatar
  • 1,089
3 votes
1 answer
327 views

Querying Opportunities related to a contact return only Open Opportunities

I am doing subquery Of Opportunities on Contact as follows:- Select id,(select id from Opportunities) from Contact where id in (select ContactId from OpportunityContactRole) I know this will return ...
sanket kumar's user avatar
  • 14.5k

1
2 3 4 5
18