Questions tagged [subquery]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
2 answers
115 views

Can I filter a query for a subquery object size?

What I'm trying to accomplish is to retrieve some Account records where a subquery item size is > 0 For example: Select id, (select id from relatedItems__r) from Account where (relatedItems__r....
Frans's user avatar
  • 29
0 votes
1 answer
42 views

Running a query to see the comparison of bounce count to # of block bounces and my query is returning 0

Here's my code. I tested the subquery and it returns records. But when I join it it returns nothing for some reason. SELECT sub.SubscriberKey ,sub.BounceCount ,sub.Status ,bb.BlockBounceCount ,(sub....
en-rep's user avatar
  • 25
0 votes
0 answers
57 views

Get list of all users of a public group that match criteria A or criteria B or both

I have a public group comprising six users: UserOrGroupId IsActive 001 true 002 false 003 true 004 false 005 false 006 true I would like to retrieve a list containing all active group members ...
user369137's user avatar
-1 votes
1 answer
137 views

Nested Query for LWC [duplicate]

public static List<WrapperToLWC> getList(String namee){ Id cleanId = (Id) namee; List<SObject> membersList = new List<SObject>(); membersList = [SELECT Id, SObject1, Rol, ...
TechGuy's user avatar
  • 97
0 votes
0 answers
71 views

ContentDocumentLinks subquery stopped working

I previously had this code and it was working (ContentDocumentLinks as related list subquery): List<Id> recordIds = new List<Id>{'0032200000SRusR'}; List<Contact> contacts = [ ...
Mariia Illarionova's user avatar
0 votes
0 answers
433 views

Retrieve external id info within specific object query

I am new to Salesforce and I'm trying to figure out a SOQL query that would work easily in normal SQL. I am retrieving specific objects (O) based on a value, but I also want to retrieve the values ...
Stephen Romero's user avatar
1 vote
1 answer
513 views

SOQL Subquery - Getting Cases that have updated ContentDocumentLinks (Attachments)

I have an integration that pulls cases using the following query. This works well. SELECT id, casenumber FROM case WHERE LastModifiedDate >= 2022-02-21T22:08:01Z AND LastModifiedDate <= 2022-...
Nayrb's user avatar
  • 113
4 votes
1 answer
221 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
-1 votes
1 answer
416 views

Child to parent SOQL query inside a parent to child query

I need a query to get the Name of the records referenced in the WhatId and OwnerId fields of the ActivityHistories related to a contact. How can I go about bulding this query? This is what I have so ...
Crimson97's user avatar
1 vote
1 answer
2k views

Filtering query results where subquery returns no rows

I'm trying to filter out query results when a subquery doesn't return rows, however, I'm still getting null results... Will someone please tell me what I need to do differently? SELECT afc.ID, ( ...
Layton Everson's user avatar
0 votes
1 answer
36 views

How to access custom date field inside the subquery?

I am unable to retrieve one custom date field which I created in the custom object which I have coded inside my sub query. The date field is visit_date__c inside the custom object Location__c in ...
Brindha Sharadha's user avatar
0 votes
1 answer
336 views

Retrieve Owner Name from the Sub Query to use in Datatable

I am trying to get the Owner Name of the Task that is associated with the contact and display it in the lightning component. The Sub Query for retrieving the Tasks associated with contact is below ...
user81642's user avatar
  • 667
1 vote
1 answer
891 views

SOQL Sub Query to retrieve the Owner Name

I am trying to retrieve the Tasks associated with the contact by doing the Sub Query like below Select firstname,lastname,(SELECT Id,Subject,Owner.Name FROM Tasks where Status = 'Completed' ORDER BY ...
user81642's user avatar
  • 667
1 vote
1 answer
509 views

Select foreign key for sub query when there are more than one candidates

In our Asset object, we have the standard Contact field (who, in our case, is the person who purchased the Asset). We also have a second Lookup(Contact) called Member__c who is the beneficary of the ...
cyberspy's user avatar
  • 200
0 votes
1 answer
146 views

Please help with a subquery that includes Order By and a second child relationship

I've learned a lot about Salesforce querying but also have a lot to learn. I hope this question is clear. I have a lookup relationship where Restrictions__c is the parent and Actions__c is the child (...
Lynda's user avatar
  • 1
3 votes
1 answer
2k views

Are subqueries supported in SFMC SQL?

When I try the following test of a subquery in SFMC Query Studio, I get the error message "Unable to create temporary data extension: Field name cannot be blank." According to official ...
alanng's user avatar
  • 33
1 vote
1 answer
394 views

C# get subquery records of custom object

Let's say I have a query like this: Select Name,Color, (select Id,Amount from Custom_2__r) from Custom_1__c Where Custom_1__c.Id='111' In C# I see that 'Custom_1__c[0].Custom_2__r' is of type ...
LeeFranke's user avatar
  • 335
1 vote
2 answers
710 views

Parent to Child Query on Contact and FinServ__ContactContactRelation__c object

I wanted to write parent to child query between Contact and FinServ__ContactContactRelation__c (Financial cloud standard object). In CCR object, both FinServ__Contact__c and FinServ__RelatedContact__c ...
Mahesh Raghuraman's user avatar
0 votes
0 answers
84 views

Query running in developer console but not through Force client in .Net

Following query runs fine in developer console and workbench but fails in .Net code which uses Force Rest client: Select Id, Name, (select contact.id, contact.firstname FROM account.contacts), (...
Haris's user avatar
  • 101
1 vote
2 answers
4k views

Using Multiple SOQL Subqueries

I am currently in the process of bulkifying some trigger code. On a high level, I receive a list of Contact objects, then I need to find the Account associated with it, and count the number of primary ...
Douglas's user avatar
  • 45
1 vote
1 answer
746 views

Custom metadata types - subquery relationship name

Is it possible to use Custom Metadata Types in the subqueries? If yes, how? In my case, there is a custom metadata type named Custom Actions and there is a Next_Action field in it. When I query for ...
Lafexlos's user avatar
  • 499
1 vote
1 answer
1k views

Subquery in WHERE clause with multiple fields

I wonder if SOQL ever support multiple fields in WHERE subquery... Something like this (hope, it's self-explanatory): select whatever from Table1 where (Field1, Field2) in (select Field3, Field4 from ...
Andriy Kovtun's user avatar
0 votes
0 answers
151 views

Need SOQL help with subquery

I need a query on Accounts and it's related active Instance where an Entitlement of that Account for a specific product is active. Instances and Entitlement do not have a relationship on their own. ...
Jack's user avatar
  • 1
1 vote
1 answer
57 views

Sub query result is 0

I want to get the Opportunity Ids of the Opportunity records that have associated OpportunityLineItems but no Revenue_Pipeline__c custom object records for a batch class. I have my sub-query which ...
Dan Wooding's user avatar
  • 3,478
0 votes
1 answer
3k views

Extending WHERE clause with condition from another query

I have two different queries which give the results, however is there a way to combine 2 queries and extend the WHERE clause as below: Query 1 SELECT Id, Name, (Select ID, Name, Object_C__r.Name ...
Salesforce Learner's user avatar
1 vote
2 answers
502 views

Combine and Query 2 Child object to a Parent Object

I was wondering can you combine 2 child objects to a parent object. SELECT SourceIp FROM LoginHistory WHERE UserId IN (SELECT Id FROM User) SELECT City FROM LoginGeo WHERE CreatedbyId (SELECT Id ...
maestro's user avatar
  • 11
0 votes
2 answers
202 views

Rewrite query to make it without subqueries

I have some custom objects displayed on schema. I need return vacancies which have last active interview at least week ago. I have some query: List<Vacancy__c> ids = new List<Vacancy__c>(...
Ostap Obervan's user avatar
-1 votes
1 answer
25 views

The system saves the records that fired the before trigger after the trigger finishes execution? [closed]

trigger HelloWorldTrigger on Account (before insert) { for(Account a : Trigger.New) { a.Description = 'New description'; } } Copy
viswanth183's user avatar
1 vote
1 answer
378 views

Flatten SOQL Subquery to return 1 row per ActivityHistory

I currently have this query: SELECT (SELECT CallDurationInSeconds, CallData__c, Closed_After_DueDate__c, Reminder_Date_Time_LEX__c, PrimaryWhoId, Current_User_Assigned__c, LastModifiedById, ...
Rafael Barros's user avatar
3 votes
1 answer
352 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
1 vote
1 answer
1k views

How to iterate sub query on lightning page

I want to display the contact names and opportunity names where AccountID is not null, I am able to display the contact names, can someone please help me to display the opportunity names too? Below ...
gs650x's user avatar
  • 2,600
3 votes
2 answers
1k views

Left outer join safety in SOQL

I covered this post. There I met the following query: SELECT Name, (SELECT Name FROM Job_Applications__r) FROM Position__c Here is the explanation provided in the post: Note that we have utilized ...
iloveseven's user avatar
  • 1,105
0 votes
1 answer
262 views

parent-child relationship subqueries not contributing to governor limits

As per the article Execution Governors and Limits In a SOQL query with parent-child relationship subqueries, each parent-child relationship counts as an extra query. The row counts from these ...
Cuban coffee's user avatar
  • 1,532
0 votes
1 answer
7k views

Query for parent-to-child (lookup) [duplicate]

I need to query all the related children of an object, the connection is via a lookup relationship. Query as follows to illustrate: SELECT (SELECT Id FROM Orders) FROM Invoice__c Error message: ...
Cuban coffee's user avatar
  • 1,532
0 votes
1 answer
1k views

How to loop trough subquery relations [MAP] and put all in 1 [MAP] [closed]

I have a before insert trigger where Relatietype__c is a junction object on contact and account. I need to compare these with a 3rd object Huishouden__c with the Huishouden__c.name field which is a ...
Thomas's user avatar
  • 2,294
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
0 votes
1 answer
269 views

Why my soql query is returning 'RecordTypeId' instead of the fields mentioned in the query? [duplicate]

Why my soql query is returning 'RecordTypeId' instead of the fields mentioned in the query? Here's my query: SELECT Id, Name, ABC, (SELECT Id, XYZ FROM InnerObject) FROM OuterObj Note: My query ...
Surya's user avatar
  • 37
0 votes
1 answer
31 views

What is the Correct collection class structure to hold SOQL subquery results?

I've got a scenario where a status field on the parent object needs to be updated to reflect the status of the most recently created child object. To solve this, I've done a SOQL with a subquery :- ...
Rob Cowell's user avatar
2 votes
1 answer
700 views

Cannot use ALL ROWS in a SOQL subquery?

I need to query all Tasks from a Case, and some of the Tasks are over a year old, which makes them invisible to SOQL unless you use the ALL ROWS keyword. I tried to use ALL ROWS in the subquery, but ...
Kirill Yunussov's user avatar