Skip to main content

Questions tagged [relationships]

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

Filter by
Sorted by
Tagged with
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
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
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
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
14 votes
1 answer
785 views

Can someone confirm if I've identified a bug in Salesforce regarding formula fields?

I believe I've identified a bug in Salesforce related to formula fields. Can some of my fellow developers, and admins too, confirm if I am observing unexpected behavior? I do have a workaround. The ...
Coogle's user avatar
  • 445
13 votes
3 answers
4k views

Do child/parent relationship names need to be unique?

Don't all child relationship names on an object need to be unique ? I know they need to be unique if it's a relationship name on a parent to child relationship, but I thought they still needed to be ...
Zoom_v's user avatar
  • 3,884
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
44k 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
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
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
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
1 answer
2k views

Why does the documentation stipulate that a many-to-many object relationship requires two master-detail relationships?

In theory you can model a many-to-many relationship using lookup fields exclusively or in combination with a master-detail field. However the documentation only mentions master-detail fields. What ...
Wes Nolte's user avatar
  • 2,136
10 votes
3 answers
911 views

Which is faster between static and dynamic getSObjects?

What is the difference in execution between . (dot) notation and getSObjects method? Omitting of course that I can parametrize with string getSObjects method. for example: Account....
patryk's user avatar
  • 655
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
9 votes
1 answer
4k views

How to initialize sObject with Relational fields?

In Lightning component we have relational fields (e.g. CustObjA.CustObj__r.Name) which we use in lighthing component. This is on component as, <ui:inputText class="slds-input" value="{!v.Item....
Pasan Eeriyagama's user avatar
9 votes
1 answer
4k views

Relationship query on Custom Metadata Type giving wrong results

I have a parent Metadata Type having a child relationship. SOQL behaves differently in each of the following scenarios: SELECT ALLFIELDS, (SELECT ALLFIELDS FROM Children__r ORDER BY Order__c) FROM ...
Mossi's user avatar
  • 3,966
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
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
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
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
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
8 votes
1 answer
1k views

Lookup Relationship question

I'm still new-ish to SF, so sorry if this is a stupid question. Set-up I create an object, test, and at creation I allow activities to be associated with that object. Test has a lookup ...
PartOfTheOhana's user avatar
8 votes
2 answers
5k views

Accounts with many-to-many relationship with accounts -- how to create a report on contacts

I'm setting up an org that has a many-to-many relationship between "buyers" and "sellers." I'm using the Account object for both buyers and sellers and set the Type field picklist to have the choices ...
djackiem's user avatar
  • 179
8 votes
4 answers
5k views

Bulk API & Foreign Key Resolution on Lookup Fields

We are designing an Integration leveraging Bulk API & Enterprise WSDL (The client code is handled by the source system). The target Force.com Object has few Lookup Fields. Wanted to understand how ...
KaLi's user avatar
  • 1,519
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
7 votes
2 answers
1k views

Are the related objects in an SOQL query shared?

I have an SOQL query between two custom objects, let's call them A__c and B__c, where A__c has a Lookup field called B__c that references a B__c instance and B__c has two fields X__c and Y__c like: ...
Phil W's user avatar
  • 36.8k
7 votes
3 answers
644 views

SOQL Query to retrieve Contacts from an Account sorted by the distance between the contact location and the account location

I'm trying to create a SOQL query to retrieve Contacts from Accounts, with the contacts for each account sorted by the distance between the contact location and the account location. This is what I ...
KB145's user avatar
  • 876
6 votes
2 answers
3k views

SOQL Outer Join Multi Level Master Detail Relationship

I am working with a 3 Level Master Detail Object Relationship: "Level 1" has "Level 2" detail records "Level 2" has "Level 3" detail records I am trying to Query "Level 1 records" and using an ...
Justin J Carlson's user avatar
6 votes
1 answer
238 views

Odd child relationship names

I have a object where the child relationship name is R00NR0000000Q8eeMAC instead of something more descriptive. How did that happen? Could it have been because the developer was working in Eclipse ...
Jagular's user avatar
  • 3,356
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
6 votes
1 answer
694 views

SOQL query with inner query doesn't recognize understand the relationship

I'm trying to write a SOQL query that will retrieve a list of Content sObjects and return it's related child Attribute sObjects. First I wrote the SOQL query to grab the parent records, and it ...
splatto's user avatar
  • 173
6 votes
1 answer
1k views

Circular Lookup Reference

We have two objects "Project" and "Project Members". Project is child of some other object with master-child relationship. So, we can't have "Master-Detail" relationship between "Project" and "Project ...
Ashish's user avatar
  • 2,372
6 votes
0 answers
304 views

APEX Schema ChildRelationships: why have some relationships their relationshipName = null?

There is some strangeness in the some standard Childrelationships. Most Relationships are as expected, but let us take Account and Quote as an example: On Quote we have a standard lookup field Quote....
Uwe Heim's user avatar
  • 28.4k
6 votes
2 answers
1k views

Is possible to relate Data Categories to custom objects records?

I have some data in Knowledge and Answers that I'd love to relate to other data in custom objects? Is it possible to refer data categories from custom objects, besides sort of manually (and ...
Keith Mancuso's user avatar
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
4 answers
7k views

How do Junction Objects - Many To Many Relationships - work?

I have read about many-to-many relationship in Salesforce and it is possible through Junction Object. That I got, but what I haven't got is that "How it works internally ?" Please help me to visualize ...
Vickal's user avatar
  • 592
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
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 ...
5 votes
6 answers
37k views

How many master-detail relationships per object?

All I see online is that each object can have 2 master-detail relationships, but on the Salesforce App Limits PDF : https://na5.salesforce.com/help/pdfs/en/salesforce_app_limits_cheatsheet.pdf It ...
newuser's user avatar
  • 149
5 votes
2 answers
4k views

Cannot access owner fields in new instance of child object even though OwnerId is populated

I have CustomObject__c that has the standard Owner field (which is a lookup field to a User). My code is the following: User myUser; //assume I've populated myUser as a result of a SOQL query or ...
Danny's user avatar
  • 153
5 votes
1 answer
1k views

Query and Follow Owner Relationship on Tasks

I actually can't believe I've not come across this before now, but is there a way of following on the owner relationship on a Task to get some other field on the User object? For an example, say on ...
Matt Lacey's user avatar
  • 25.7k
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
5 votes
2 answers
3k views

Child object with two parents - will child still exist if if I delete one parent?

I have doubt in the Parent-child relationship .Suppose I have scenario where an object is in a relationship with two parent objects. In that relationship if I delete one parent object, will the child ...
satish's user avatar
  • 143
5 votes
1 answer
12k views

Difference between a self relationship and Lookup relationship

With Self relationship you can reference the same object, at the same time you can create a lookup relationship and still refer to the same object. So when do you call a relationship as self vs lookup....
user5352's user avatar
  • 1,675
5 votes
1 answer
11k views

INVALID_FIELD, Foreign key external ID not found - Inserting Related Records via External Id

I am trying to insert related records via an External Id. i am using an approach described here where we create an empty parent object with the same external Id like the "real" parent. It is a self-...
Robert Méndez's user avatar
5 votes
2 answers
811 views

Invalid foreign Key error

I keep getting this error on this code and i am not sure how to fix this. Invalid foreign key relationship: Lead.channel_sales_manager__c The line with the errors is in * trigger leadassign on ...
user24287's user avatar
5 votes
1 answer
2k views

Find all records referencing a specific Account

What would be the best way to go about listing all the records that reference an Account? Lookup Ids aren't search indexed so SOSL turns up no results when looking for the Account Id and the only ...
Valyrion's user avatar
  • 1,144
5 votes
2 answers
4k views

Is it possible to get the "type" of object you're querying in a SOQL relationship query

For example, in the standard Salesforce Event object, I'd like to do the following with the WhatId field. select what.name, what.type(?) from event where id = 'myid' However, this will only work if ...
contactmatt's user avatar
  • 1,069
5 votes
1 answer
4k views

How to retrieve a value from a parent field with SOQL via partner API in java

I have a parent-child relationship with timesheets relating to users. I am trying to retrieve an Employment ID field from the parent record with SOQL and this is my query, where the UserID is a field ...
Kent's user avatar
  • 157

1
2 3 4 5
11