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
-1 votes
1 answer
195 views

How to delete records and related records dynamically from SObjects

My Production org is almost full I need to delete Objects data and their related objects data based on SObjects mentioned in custom metadatatype. I have written code to delete SObjects and related ...
jagadeep's user avatar
0 votes
2 answers
431 views

How to query managed package objects

I'm trying to retrieve record values of a managed package custom object (call it abc__custom_object__c, where 'abc' is the package namespace, as an example). Trying to run the following SOQL query ...
lhh13's user avatar
  • 41
-2 votes
1 answer
69 views

List all contacts that don't have an Attachment with given Title SOQL

iIs it possible to list all Contacts that don't have an Attachment with given title 'X'? Or select Contacts without Attachments at all? New to SF, making integration to find contacts with missing ...
Roma Roik's user avatar
-3 votes
1 answer
317 views

How to do pagination using apex and LWC without using OFFSET or WHERE clause to showcase records

I want the logic to be in apex. QueryLocator, queryMore etc have limited application seen with reference to this. I am currently trying to query all the records and slice them accordingly. But, this ...
Bhavya Manjusha C's user avatar
1 vote
1 answer
139 views

Rusty Coder - Better way to avoid soql in loop

I haven't had to write any code in a few years now and I have to believe I am not using the best approach to avoid a SOQL query in the loop. I am doing a query outside of the loop and then iterating ...
Matt M's user avatar
  • 1,473
1 vote
2 answers
232 views

How to get the list of custom fields in my org which are used nowhere

How to get the list of custom fields in my org which are used nowhere? I tried to do SOQL query MetadataComponentDependency object using Tooling API to get all component dependency records, but only ...
Aritra Chakraborty's user avatar
0 votes
0 answers
87 views

Get history of groupmember/queue assigned to user

I'm trying to check the history of groupmember assignments which was done to a specific user, I know that we have the GroupMember table to query the current assignments like: Select Id, GroupId, Group....
Tony Marques's user avatar
1 vote
0 answers
72 views

What are the correct security settings to use when performing a SOQL query on ContentDocumentLink or ContentVersion?

We are building a small LWC for browsing images that users have uploaded to our organization through the built-in Files support. Our users are able to properly see the Files when accessed through the ...
kennyc's user avatar
  • 307
0 votes
2 answers
85 views

Combining where and having clauses in group by

I am running a group by query. As part of this, I want to check the sum of one field, and then check if that sum exceeds a number. The number itself depends on the value of a second field, which is ...
hamayoun's user avatar
  • 2,727
-1 votes
3 answers
223 views

How to use Custom Setting variable in LAST_N_DAYS

I am trying to write a SOQL query which uses the Custom Settings. Basically, trying to query all the records of a Custom Object of the last 30 days. I am trying to use a custom setting Number_Days__c ...
Accredo2442's user avatar
4 votes
1 answer
133 views

How can I prevent a ContentDocument being deleted when it is linked to a record meeting certain criteria?

I have ContentDocuments being used to capture "proof" against certifications. Once the submitted certification (and "proof") has been reviewed, that certification is marked "...
Phil W's user avatar
  • 34.3k
0 votes
1 answer
95 views

Salesforce Bug: Cannot Order By Id on SiteDetail after API Version 49

This seems to have been introduced with Summer '23 as my scratch orgs just did the swap over the weekend. I can't query for SiteDetail with an ORDER BY Id in the query. Steps to Reproduce: Create a ...
Jake Richter's user avatar
  • 1,351
0 votes
0 answers
187 views

Return list of records based on soql query results

I have two objects that has a many to many relationship with each other. Ideally, I would create a junction object for this but it would be data heavy hence we're trying to avoid it. I was thinking ...
sidies's user avatar
  • 1
0 votes
1 answer
30 views

Case Sensitive LIKE query fails for same letter with different cases

I have a custom string field, that is explicitly marked as Case Sensitive. When I query for this field, like so: SELECT field__c FROM Object__c WHERE field__c LIKE 'a%' OR field__c LIKE 'A%' I ...
luksfarris's user avatar
1 vote
2 answers
136 views

How to perform a SOQL in clause using Apex Enterprise Patterns Selector?

I'm setting an an AEP Selector which needs to implement the following: [select ParentId from SetupEntityAccess where SetupEntityId in (select Id from CustomPermission where DeveloperName = :name)] ...
Swisher Sweet's user avatar
1 vote
1 answer
271 views

Getting the top level parent account of an account in hierarchy

I have written a class that gets the id of the top level account in the hierarchy of the given account id. public class AccountUtils { // Create a Map to hold Account Ids and their parent Ids ...
Tony Jude's user avatar
0 votes
1 answer
105 views

SOQL query not working with GROUP BY in semi-join

Why is this SOQL query not working? I'm trying to retrieve duplicate accounts, by I need the Id for each specific account that's why I didn't just use the subselect query which would give me a grouped ...
Hebano Duffrayer's user avatar
0 votes
1 answer
580 views

how to query the fields of a managed package object

I am trying to query list of fields for certain objects, have the following query which works fine for standard and custom objects but now for managed package objects. SELECT QualifiedApiName, ...
Sam's user avatar
  • 83
1 vote
1 answer
324 views

How to Delete record from the AuthSession Object?

I have a requirement to test user authentication to see if a user can potentially login to an experience site with their credentials but then to not allow the actual login. To achieve this I used the ...
Shaun van Huyssteen's user avatar
-2 votes
1 answer
279 views

How to get data from two different object with same field if there is no relation between objects using SOQL

How to get data from tow different object with same field if there is no relation between two objects using SOQL there is one common field between two objects. I am trying the below query : select Id,...
Somesh's user avatar
  • 1
-2 votes
1 answer
73 views

The Error in this code is - validate CRUD permission before SOQL/DML operation (rule: secuirity - apexCRUDVioloation) what is the probable solution?

public with sharing class VehicleController { @AuraEnabled(Cacheable=true) public static List<Vehicle__c> getVehicleList() { return [SELECT Id, Veichle_Name__c, Rental_Rate__c, ...
SOMANKAR CHAKRABORTY's user avatar
0 votes
1 answer
168 views

Security scan is complaining on setEndpoing

My company uses a security scan tool called Snyk to scan code for security vulnerabilities. It is complaining about a Server-Side Request Forgery (SSRF) vulnerability. The details says Unsanitized ...
James's user avatar
  • 329
-1 votes
1 answer
67 views

SOQL - how to pull list of all Asset records for an Account only if two specific Assets are present?

I’ve been tasked by our sales leadership to run a report that lists all Accounts that have 2 specific Assets. Easy enough right? However, they want to display the list of all assets under those ...
Lobece Favilu's user avatar
0 votes
1 answer
44 views

How to use sort by in Apex code when using SOSL queries from different tables

Here is the code of the visualforce page: public class moderatorpanelCtrl { Task tk; public list< LoginHistory> Task {get;set;} public list< TopicAssignment> TP {get;set;...
Vishnu Vardhan's user avatar
-1 votes
1 answer
236 views

How to load more than 255 chars data in Text Area as seperate line

How to load more than 255 chars data in Text Area as seperate line when pushing data from Mule soft is there any line break can we add
Somesh's user avatar
  • 1
0 votes
1 answer
90 views

SOQL to get list of users related to a specific parent account

I'm trying to create a query that will fetch all the users that are associated to the parent account of an specific account. Both accounts are PersonAccount entities. So, basically I only have the &...
fingerprints's user avatar
0 votes
1 answer
88 views

ObjectHistory sort is not working correctly (UI as well as in SOQL)

Hoping someone has in idea into what is going wrong with history object record entry and sorting. Here is the soql query i'm running: SELECT Id,Field,OldValue,NewValue, CreatedDate FROM "...
Mavsav Sauve's user avatar
1 vote
1 answer
81 views

Nested SOQL is working but nested joins are not working

With Summer '23 release we can query upto 5 levels down in Parent-Child Relationships. See this Salesforce release notes My sandbox is on Summer '23 release and I was able to test my custom objects ...
Json Bourne's user avatar
-1 votes
1 answer
59 views

Apex Controller to get the total no of Accounts and Opportunities group by Owner Name

I have a requirement to get a table as below, I was creating an apex controller as below, but its showing issues, May i know where i get wrong ? public class AccountController { public <...
Sourav's user avatar
  • 15
-3 votes
2 answers
50 views

How Can make my query dynamic, I found error inside this query? System.QueryException: expecting a colon, found 'Regional'

String userFields = 'user.id, user.profile.name'; String profileName = 'Regional CS Team Member'; String userObject = 'user, user.profile'; String userCondition = 'user.profile....
Preeti Kant's user avatar
3 votes
1 answer
169 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
  • 135k
-1 votes
1 answer
25 views

Subquery in cross object

I've got 3 objects => -Object A has a lookup with Object B (Order) -Obect C (case) has a lookup with Object B I need to retreive a field on Object C to display with all the field from the Object A (...
Laetitia Da's user avatar
0 votes
2 answers
117 views

Why do these two queries return different results?

I have a requirement to get the most recent task date on an account. When I use the following query, Salesforce does not return the correct answer. If I do the same query but on the task object, the ...
Pauline's user avatar
  • 353
0 votes
1 answer
287 views

How to determine fields for which a given profile does not have read permission

Full disclosure, my expertise is not on the Salesforce side, but in .NET and SQL; however, I've been tasked with assisting my company with a data migration from our original org to a new one. The in-...
JTennessen's user avatar
1 vote
3 answers
303 views

How to do this in one SOQL

I have a query where I need to retrieve a list of Accounts and their related childs "Commission Imports", but I only need the latest of these. I determine which is the latest based on two ...
David de León's user avatar
0 votes
1 answer
202 views

How to use checkbox=true in DLRS relationship criteria?

I'm trying DLRS for the first time and I need help with an SOQL error. I'm trying to count related contract records for each contact where tutor=true (in orange). In my contract object, I have a ...
Sebbie's user avatar
  • 29
-1 votes
1 answer
75 views

How to avoid SOQL Query in the for loop in this scenario

How to avoid the SQL Query in this case public static void sendSMS(List<Case> newList){ List<Case> selectedCases =[SELECT Id , ...
Abanob's user avatar
  • 1
0 votes
1 answer
106 views

Related list on visual page rendered as PDF

I'm trying to build a custom invoice in Visualforce page rendered as PDF, in which I'm using Opportunity as my standardController. However, I'd like to get the list products related to the Opportunity ...
Gabriel Gessen's user avatar
3 votes
1 answer
49 views

I'm only allowed to use certain fields in SOQL run through sfdx

I'm working on a MacBook Pro, so I log into production via a browser, then I open a Terminal window and I authenticate: sfdx auth:device:login -r https://blue.my.salesforce.com I type in the code and ...
charlottesville's user avatar
1 vote
3 answers
136 views

Query Lookup Relationship With SOQL Not Working

I have a SalesForce custom object named Loan__c which has a Lookup field called LoanLead__c and I'm trying to query that relationship with SOQL but I'm getting an error when I run the query SELECT Id, ...
Daniel Phillips's user avatar
1 vote
1 answer
62 views

Query knowledges and datacategory names in a multi language org

The article knowledges are written in two languages: dutch (master) and french. When I run this query: SELECT Id, Title, language, articleNumber, ( SELECT Id, DataCategoryName FROM ...
Sarah De Cock's user avatar
0 votes
1 answer
707 views

How to use tooling api to query data in Apex [duplicate]

I want to retrieve the test-coverage with tooling-soql query SELECT ApexClassOrTrigger.Name, NumLinesCovered, NumLinesUncovered FROM ApexCodeCoverageAggregate ORDER BY ApexClassOrTrigger.Name ASC It ...
Shubham Jangid's user avatar
-3 votes
1 answer
45 views

I am new to salesforce and performing this query getting error

SELECT Name, Account.Id, Contact.Email FROM Opportunity WHERE Amount > 500 AND Contact.Email != '' Please explain me where I am wrong.
Sophia's user avatar
  • 3
0 votes
0 answers
89 views

Big Objects are not inserting properly but got successful message while inserting

I have inserted 50 records from email message (standard objects) to big objects by apex(database.insertimmediate). All 50 records are inserted successfully. But in big objects, i could see only 8 ...
Yeswanth's user avatar
0 votes
1 answer
357 views

Passing a List in SOQL Query

I'm trying to pass a list of 1000 account IDs and retrieve their corresponding count of Contacts and write the results to a CSV file. I'm using the Anonymous Execute window to run the code below as I ...
ManiS's user avatar
  • 3
0 votes
1 answer
655 views

How to retrieve reportFolder.meta-xml files with the Access Type and ParentId attributes?

One can retrieve reports/dashboards via sfdx or via package.xml easily but when trying to deploy them to another org, errors like 'report folder doesn't exist' are hit if the report/dashboard is in a ...
Andy Hitchings's user avatar
1 vote
1 answer
115 views

to get id in the place of index number in for loop

I have a method on which I'm running loop for showing all records of particular user(account). I'm getting index number in result. I want to show id of user instead of index number. public static ...
Abhishek Sharma's user avatar
0 votes
2 answers
42 views

I am executing the below SOQL to get list of all upload documents today from Content Document object but for some reason I am not getting all the docs

Can you please guide me in this. SELECT Id, Title, ContentSize, FileExtension, CreatedDate, CreatedById, createdby.name FROM ContentDocument where CreatedDate = TODAY Also, this is working fine in ...
AronSFDCAdmin's user avatar
-2 votes
1 answer
848 views

Steps to query data directly from Apex, and return the values to my LWC?

My goal is to get the metadata for all my Opportunities in Salesforce (the address, city, and state). I was told to look into query data directly from Apex, then I can return those values to my LWC. I'...
Pinto's user avatar
  • 128
-1 votes
1 answer
58 views

Is it required to use the Developer Console to query data from Apex?

I want to query my object data directly from Apex. I was wondering if its required to use the 'Developer Console' in Salesforce, or if I can use VS Code? If you can do both which would you recommend?
Pinto's user avatar
  • 128