Skip to main content
New
Stack Overflow Jobs powered by Indeed: A job site that puts thousands of tech jobs at your fingertips (U.S. only). Search jobs

Questions tagged [relationships]

Use relationships to associate an object with other objects in Salesforce.

Filter by
Sorted by
Tagged with
18 votes
1 answer
3k views

Set Relationship Via Name Pointing Field?

One of the most startling things I ever learned from @BobBuzzard is that you can update a lookup by using the name pointing field. At least, I thought that's what I learned, until a recent debate cast ...
Adrian Larson's user avatar
  • 150k
5 votes
1 answer
2k views

Why can't I see related data in my Apex, or why are related records showing up as `null`?

This is a canonical question and answer developed by the community to help address common questions. If you've been directed here, or your question has been closed as a duplicate, please look through ...
24 votes
5 answers
32k views

Difference between __c and __r?

I read this article for difference between __r and __c. But I still can't understand how is Hiring_Manager__c.Email will be different from Hiring_Manager__r.Email Can anyone explain this? Thanks in ...
MnZ's user avatar
  • 3,170
8 votes
1 answer
9k views

SOQL: Comparing two custom relationship fields in a nested query

I think I may be hitting some sort of SOQL limitation in the WHERE clause. I am trying to return fields from two parent objects, after comparing two date fields on both Objects. The goal is to have a ...
ZAR's user avatar
  • 2,043
4 votes
2 answers
4k views

How to use GetSObject to retrieve related data in a null safe manner?

I have a lookup relationship. If I just do the following query it works fine: Sobject c = [select field__r.fieldchild__c from custom_obj where Id = :someId]; system.debug('c:' + c); However with ...
Nick's user avatar
  • 7,022
3 votes
1 answer
4k views

Before Insert: Using __r to pull related data in a Trigger.New for loop results in nulls even though lookup relationship has Id

Situation: I am trying to build a custom validation rule via apex that will stop users from saving a charge item to a quote if the charge item exceeds the available product quantity. The charge item ...
Morgan Marchese's user avatar
14 votes
7 answers
41k views

Relationship between account and contact

I checked 'Account Name' field in Contact object. It appeared as a Lookup(Account). But when I deleted that account, contact also got deleted which tells me it is a master-detail relation. Can anyone ...
MnZ's user avatar
  • 3,170
7 votes
4 answers
2k views

Mandatory child record when creating parent record

The standard object Account has a master-detail relationship with a child object called Address__c. In the Address__c object we store the various addresses an account might have. My question is as ...
Mihai Neagoe's user avatar
  • 3,192
1 vote
1 answer
639 views

Navigating lookup relationships with dot notations, to retrieve field values

I need to access the value from a roll-up field on my Opportunities, from it's related Opportunity Product. When I use oli.Opportunity.Software_Line_Item__c the value retrieved is always null. So I'...
Alex S's user avatar
  • 2,306
8 votes
4 answers
5k views

How to identify look up relations to an object in Salesforce

I have a custom object and I would like to know which all other objects have look up relations to this one? There are many objects available and I cannot go into each and identify which would have ...
stack_pointer is EXTINCT's user avatar
3 votes
1 answer
11k views

Relationship between Account and Opportunity and Account and Contact

On Opportunity there is a lookup relationship to Account.But why it behaves as Master-Detail as we can create Rollup Summary Fields on Account. Similarly if we delete Account then Contact gets ...
sfdc's user avatar
  • 13.7k
1 vote
1 answer
2k views

Event parent relationship fields are null in trigger

I am populating a junction object on from Events and want to capture info from the Event but getting the Account from Account field pulls null. Same who the name via the Who. But if I query the Event ...
jaw999's user avatar
  • 1,315
0 votes
1 answer
2k views

How to get the name of the relationship for inner queries in SOQL? [duplicate]

In Trailhead we have the query to get the Contacts for the Account named "SFDC Computing", with an inner query. SELECT Name, (SELECT LastName FROM Contacts) FROM Account WHERE Name = 'SFDC Computing'...
ElHombre55's user avatar
12 votes
1 answer
18k views

SObject row was retrieved via SOQL without querying the requested field:

I am getting this error with the code below. I've looked into the other cases on here. In my case I am referring to a relationship name (__r) which I am assuming is pulling correctly. It's a field ...
Zoom_v's user avatar
  • 3,884
6 votes
2 answers
3k views

Junction object fields

I have created a many to many relationship between two objects, A and B, using a junction object. That works fine, and the related lists show up on A and B with standard layout pages. Is it possible ...
Chuckels5584's user avatar
4 votes
2 answers
496 views

Reading and writing child relationships of not-yet persisted SObjects?

I have a Parent__c and Child__c custom object connected by a lkp_Parent__c field. I now create an in-memory version (no insert) of a parent-child tree Parent__c p = new Parent__c(); Child__c c = new ...
Robert Sösemann's user avatar
24 votes
5 answers
6k views

How to apply uniqueness on Junction object?

I have a junction object C of A and B. I found out that I can create multiple entries of A and B in Object C - this is wrong, as in my case, each combination of A and B should appear only once in ...
Saariko's user avatar
  • 5,610
4 votes
3 answers
11k views

How to find out relationships for SOQL queries?

I want to construct a SOQL query displaying all Opportunities that are sorted by the Products that are associated to it. I however have a problem finding out how Opportunities and Opportunity ...
mcbetz's user avatar
  • 927
0 votes
1 answer
2k views

Field is not writeable: CAM_Members__c.Affiliate_State__c

My compiler says that this field is not writeable: Field is not writeable: CAM_Members__c.Affiliate_State__c I have this class static testMethod void AffliateTest(){ SS_Data__c ns = new ...
Torrific's user avatar
13 votes
2 answers
1k views

What is the logic for the automatic creation and update of "standard" report types for custom objects?

Question What is the detailed logic for when a "standard" report type is created/updated for custom objects or custom relationships? Background When custom objects and custom master detail ...
Ralph Callaway's user avatar
12 votes
3 answers
43k views

Error: Field must be grouped or aggregated

We have a lookup relationship between a custom object Problem__c and cases, one problem can be related to many cases. I am trying to query the field or problem records and the number of related cases, ...
PepeFloyd's user avatar
  • 8,011
11 votes
1 answer
9k views

How to identify relationship type (Lookup / Master detail) from the field api Name in APEX?

I have requirement in which i iterate through all fields of sObject and needs to identify fields which has master detail relation ship only and then get that (Reference to)object name and then further ...
Tejas Kapasi's user avatar
11 votes
6 answers
23k views

How to select only those objects that have child relationship?

Let's say I have object Parent that has a child relationship Child__r. I'd like to select only those parents that have children through SOQL. How can I do that?
ipavlic's user avatar
  • 3,736
9 votes
2 answers
17k views

Relationship between Opportunity, OpportunityLineItems(Opportunity Product), PricebookEntry, Product2 & Pricebookentry in Salesforce?

Correct me if am wrong in these relation Ship between Opportunity, OpportunityLineItems(Opportunity Product), PricebookEntry, Product2 & Pricebookentry in Salesforce. OpportunitylineItem is ...
Cloud Techie's user avatar
9 votes
3 answers
4k views

No master-detail relationship in which the User or Lead objects are the master?

Why can't we create a master-detail relationship in which the User or Lead objects are the master, any particular reason?
MnZ's user avatar
  • 3,170
8 votes
2 answers
18k views

Didn't understand relationship in FROM part of query call [duplicate]

I am trying to query the child record using the parent record id. I understand that we have to use the child relation name in the inner query to get the child records. select id, (select id from ...
SfdcBat's user avatar
  • 4,811
8 votes
4 answers
21k views

How to get nested children records more than 1 level deep via SOQL

I want to get the account child (contact) and contact child. account contact contact contact etc., I HAVE TRIED FOLLOwING CODE: List<accont> acc = [select id,name, (...
Alex's user avatar
  • 422
8 votes
2 answers
28k views

Is it possible to convert a Master-Detail relationship to a Lookup?

I'm going through the Trailhead training (here), and see the following two snippets which seem to disagree: "It’s possible to change a lookup relationship to a master-detail relationship, but not ...
loneboat's user avatar
  • 387
5 votes
4 answers
19k views

Accessing the parent sObject from the child sObject?

I have Object1__c and Object2__c which are related by a master-detail relationship (Object1__c is the master). I want to be able to query a record of Object2__c in such a way that I have access to ...
coldspeed's user avatar
  • 701
5 votes
1 answer
2k views

How to refer to an existing record in REST API composite JSON?

When using REST API composite JSON, how to refer with external id an existing record to existing Master-Detail parent from a newly created child We have the following objects: Organization__c: Has ...
Touko's user avatar
  • 151
5 votes
2 answers
30k views

What is wrong with my relationship?

I'm trying to use SOQL 'relationships' between two tables. I follow this example and it works fine: SELECT Account.Name, (SELECT Contact.Name FROM contacts) FROM Account from: https://developer....
JayDee's user avatar
  • 101
5 votes
2 answers
7k views

Accessing grandparent through SOQL

I'm trying to access a grandparent record through a SOQL query and am having some trouble. From my understanding, you can go 5 levels deep with a child-to-parent relationship in a query, so I don't ...
Embattled Swag's user avatar
4 votes
1 answer
7k views

Formula Field to Count Records in Lookup Relationshp

I want to count the number of child objects in a lookup (not master-detail) relationship. Since no rollup-summary (COUNT) fields are supported I thought I would do this: LEN(GETRECORDIDS($ObjectType....
Marc's user avatar
  • 1,725
4 votes
2 answers
2k views

Junction object in Salesforce

What kind of relation should a junction object have with it's parent objects? What I know from Salesforce documentation: The junction object should have master-detail relationships with the parent ...
MnZ's user avatar
  • 3,170
3 votes
1 answer
2k views

SOQL Relationship Query : Compare Child and Parent field value in WHERE clause

Is it possible to compare the Child and Parent field values in a Single SOQL Relationship Query ? say get me all contacts for an account which doesn't have same name as its parent account. SELECT ...
Vamsi Krishna Gosu's user avatar
3 votes
3 answers
993 views

SOQL for Winter 20 Where is this used functionality

Hi I would like to know how I can query the "Where is this used" relationship via SOQL. Generally, Metadata information on Fields can be found in FieldDefinition and Entity Particle tables, but can ...
Andrea Voggenreiter's user avatar
3 votes
1 answer
2k views

Related Custom List With Order and Inline Editing - Many to Many relationship and Junction Object

We are using three objects in this project: Contact (for authors), Paper, and junction object PaperAuthor. Paper holds all all attributes to describe an academic paper. Paper can have many Authors. ...
vlr's user avatar
  • 864
3 votes
2 answers
2k views

Question on Salesforce Relationship

I was going through a set of questions for Salesforce Certification and the below question is something where I would like to verify my answer. Question: A company has a custom object named ...
Sudipta Deb's user avatar
  • 1,261
2 votes
1 answer
2k views

Didn't understand relationship 'Opportunities' in FROM part of query call

This is a real estate development that has a Development object and a Property__c object. Properties can be related to a Development or not. Also, properties are tied to opportunities. Now I need ...
zJorge's user avatar
  • 133
2 votes
1 answer
7k views

Parent and Parent.Id with custom objects

I am attempting to adapt some code which was originallly written to work off of an Account object to now work on a custom object. Part of the code is referring to the Parent Account of whichever ...
Zoom_v's user avatar
  • 3,884
2 votes
2 answers
5k views

Related Object Fields in custom button (URL Hack)

Having a real brain freeze here. I am using some URL hacking to auto fill some fields on a custom object. USE CASE I have a custom object 'Operations Action' that is related to a case. My Case ...
Chris Duncombe's user avatar
2 votes
1 answer
2k views

Custom New Button that creates record of specific type and parent record in Visualforce Controller (No URLFOR!)

Sorry for the lengthy title. But I want to make sure that I was not able to solve my problem with the standard answers to questions like this. I have a CustomObject_c that has many record types and a ...
Robert Sösemann's user avatar
2 votes
2 answers
2k views

SFDX source pull field dependencies

I have two dependent picklists on an object created in a scratch org which are successfully retrieved with a force:source:pull. The field dependency between them, however, is not included in the pull....
Paul Taylor's user avatar
1 vote
4 answers
2k views

Is it possible to trigger a workflow outbound message when a custom related list item is added or removed?

Excuse my ignorance in all of this. I'm not well versed in Salesforce and I've been tasked with building an integration with a web app. I've hit a brick wall on things to Google to find a solution. ...
embolden's user avatar
  • 111
1 vote
1 answer
1k views

Custom Relationship Field Limit not reflecting deletes

If I add a custom field to an object that is a Lookup() in the Fields & Relationships section of an object, the Object Limits page for the object shows an immediate increase counting against the ...
user2270837's user avatar
0 votes
1 answer
8k views

Display related fields in LWC Datatable [duplicate]

Trying to display related fields from junction object linked to 2 objects vis Master Detail : @track columns = [{ fieldName: 'related_field__r.Name', label: 'Name', type: "text", ...
user avatar
0 votes
1 answer
888 views

Salesforce report relationships

I have noticed there are 3 ways to get data across related objects into reports. 1.) Custom Report Types - you can create report types with a Parent Object and traverse down related Objects. 2.) ...
TemporaryFix's user avatar
  • 2,946
-2 votes
1 answer
1k views

How to get Case Owner Name from case object [duplicate]

In Child Object(Incident) i have a field called Client ID(BMCServiceDesk__FKClient__c) this is a lookup field relates User .I need to populate Case owner field value in to Client ID. While creation ...
kumar G's user avatar
  • 25