Questions tagged [subquery]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
1 answer
46 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-...
user avatar
4 votes
1 answer
103 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 ...
user avatar
  • 193
0 votes
0 answers
30 views

Soql get record without child or matching clause

There are my query and i want to get Service_Order__c records list in order by date in both ways: when it mathicng where clause and when there are no child record ( So Service_Order__c in ...
user avatar
-1 votes
1 answer
165 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 ...
user avatar
1 vote
1 answer
259 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, ( ...
user avatar
0 votes
1 answer
24 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 ...
user avatar
0 votes
1 answer
125 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 ...
user avatar
  • 609
1 vote
1 answer
227 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 ...
user avatar
  • 609
1 vote
1 answer
86 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 ...
user avatar
  • 182
0 votes
1 answer
79 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 (...
user avatar
  • 1
2 votes
1 answer
1k 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 ...
user avatar
  • 23
1 vote
1 answer
193 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 ...
user avatar
  • 335
1 vote
2 answers
280 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 ...
user avatar
0 votes
0 answers
54 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), (...
user avatar
  • 101
1 vote
2 answers
2k 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 ...
user avatar
  • 35
0 votes
1 answer
392 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 ...
user avatar
  • 479
1 vote
1 answer
427 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 ...
user avatar
0 votes
0 answers
108 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. ...
user avatar
  • 1
1 vote
1 answer
52 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 ...
user avatar
  • 3,351
0 votes
1 answer
1k 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 ...
user avatar
1 vote
2 answers
165 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 ...
user avatar
  • 11
0 votes
2 answers
122 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>(...
user avatar
-1 votes
1 answer
23 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
user avatar
1 vote
1 answer
231 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, ...
user avatar
3 votes
1 answer
250 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 ...
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 ...
user avatar
  • 2,270
3 votes
2 answers
924 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 ...
user avatar
  • 1,107
0 votes
1 answer
207 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 ...
user avatar
  • 1,438
0 votes
1 answer
5k 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: ...
user avatar
  • 1,438
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 ...
user avatar
  • 2,116
3 votes
1 answer
4k 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 ...
user avatar
0 votes
1 answer
193 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 ...
user avatar
  • 37
0 votes
1 answer
29 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 :- ...
user avatar
2 votes
1 answer
557 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 ...
user avatar