Understanding the Salesforce Relationship and Query Execution using Health Cloud Objects
Relationship in Salesforce
Understanding the Salesforce Relationship and Query Execution using Health Cloud Objects
Relationship in Salesforce
Photo by Nathan Dumlao on Unsplash
Salesforce Objects and Relationships
Salesforce uses parent-child relationships to link objects together. There are two main types of relationships:
- Lookup Relationship — A loose connection between objects; deletion of a parent does not affect children.
- Master-Detail Relationship — A strict connection where the child (detail) object inherits security and ownership from the parent (master).
Take an example:
SELECT Id, Name, PersonEmail,
(SELECT Id, Name, ICC_DataUsePurpose__c FROM AuthorizationFormConsents),
(SELECT Id, Name, Product_ICC__c FROM Care_Program_Enrollee_Products__r)
FROM Account
WHERE PersonEmail='example@gmail.com'
LIMIT 1
We have following objects in Salesforce
- Account (Parent)
- AuthorizationFormConsent (Child)
- Care_Program_Enrollee_Products (Child)
Each child object contains a foreign key reference (a lookup or master-detail field) to the Account object.
How This Query Works
- Fetches fields from the
Accountobject:
Id,Name, andPersonEmail(basic Account fields).
- Subqueries fetch child records using relationship names:
(SELECT Id, Name, ICC_DataUsePurpose__c FROM AuthorizationFormConsents)- Fetches related AuthorizationFormConsent records where the
AccountIdmatches the parent. (SELECT Id, Name, Product_ICC__c FROM Care_Program_Enrollee_Products__r)- Fetches related Care_Program_Enrollee_Products records where the
AccountIdmatches the parent.
- Filters Account records by email:
WHERE PersonEmail='example@gmail.com'ensures only one specific account is fetched.
- Limits results:
LIMIT 1ensures only one Account record is retrieved.
Understanding the Relationships
Each child object has a relationship name (used in subqueries). Here’s how they map:

- Relationship names are plural in SOQL queries and end with
__rif they are custom objects. - These names are set when the lookup/master-detail field is created.
Understanding the Query Result
Returned Data
[
{
"attributes": {
"type": "Account",
"url": "/services/data/v48.0/sobjects/Account/XXXXXXXXXXXIAA"
},
"Id": "XXXXXXXXXXXIAA",
"Name": "example example",
"PersonEmail": "example@gmail.com",
"AuthorizationFormConsents": null,
"Care_Program_Enrollee_Products__r": {
"totalSize": 2,
"done": true,
"records": [
{
"attributes": {
"type": "CareProgramEnrolleeProduct",
"url": "/services/data/v48.0/sobjects/CareProgramEnrolleeProduct/XXXXXXXXXXXXTIAQ"
},
"Id": "XXXXXXXXXXXXTIAQ",
"Name": "Tuna - Example - CPE-01010101",
"Product_ICC__c": "Tuna"
},
{
"attributes": {
"type": "CareProgramEnrolleeProduct",
"url": "/services/data/v48.0/sobjects/CareProgramEnrolleeProduct/XXXXXXXXXXXX45IAA"
},
"Id": "XXXXXXXXXXXX45IAA",
"Name": "CareMe Oncology - exampledrug - CPE-01010101",
"Product_ICC__c": "exampledrug"
}
]
}
}
]
Key Insights
- The Account record has
Id,Name, andPersonEmail. - AuthorizationFormConsents is
null→ meaning no records exist for this Account inAuthorizationFormConsent. - Care_Program_Enrollee_Products__r contains two records:
Id:XXXXXXXXXXXXTIAQ withProduct_ICC__c: TunaId:XXXXXXXXXXXX45IAA withProduct_ICC__c:exampledrug
Conclusion
- The subqueries use relationship names to fetch child objects related to
Account. - The relationship name is based on the lookup/master-detail field name but ends with
__rfor custom objects. - If a related object has no records, it returns
null(as seen inAuthorizationFormConsents). - If related records exist, they are returned as a list (
Care_Program_Enrollee_Products__r).
메타데이터
- post_id
- a7b41eefd508
- slug
- understanding-the-salesforce-relationship-and-query-execution-using-health-cloud-objects-a7b41eefd508
- url
- https://medium.com/@kamal.maiti/understanding-the-salesforce-relationship-and-query-execution-using-health-cloud-objects-a7b41eefd508
- canonical_url
- https://medium.com/@kamal.maiti/understanding-the-salesforce-relationship-and-query-execution-using-health-cloud-objects-a7b41eefd508
- author_url
- https://medium.com/@kamal.maiti
- status
- ok
- fetched_at
- 2026-07-11 14:18:26