Relationships Interview Questions and Answers Experienced

1.What do you mean by a relationship.

Ans: Connecting two objects with each other is known as a “Relationship”.

2.What are the Types of relationship.

Ans: a] Master – Details Relationship (1:N)
b] Lookup Relationship (1:N)
c] Many to Many Relationship (N:N) (Junction Object)
d] Self Relationship (1:1)
e] Hierarchical Relationship (1:1) etc..

3. Difference between Master-Details Relationship and Lookup Relationship.

Ans:

Master – Details Relationship Lookup Relationship
Master field on Details record is required. Parent field on child record is not a required.
If Master is deleted then All Details records also gets deleted cascadingly. If parent get deleted, then its associated child will not get deleted.
Rollup summary fields can only be created on Master records which will calculate the SUM, MIN, MAX, COUNT of the Child records. Rollup summary field is not available.
If records exists in details (child) object, then we can NOT create a Master-Details relationship with a Master(parent) object. If records exists in child object, then also we can create a Lookup relation with a parent.
Master-Details Relationship is Tightly Coupled. Lookup Relationship is Loosely Coupled.
Up to 2 master-details relationships allowed per object. Maximum 40 lookup relationship can be created per object. If master-details=01, then Lookup=39. If master-details=02, then Lookup=38.
In OWD, Details Object is Controlled By Parent. Means, OWD of Parent will be applicable to Details object also. In OWD, Child object is NOT controlled by Parent.

Back to Question

4. Can we convert a Master-Details Relationship into a Lookup Relationship.

Ans: Yes, master object should not contain rollup summary field. If it is there, first delete it permanently.

5. Can we convert Lookup Relationship into Master-Details Relationship.

Ans: Yes, but all child record should be associated with their related parents first. Means, no child should be there without the parent.

6. Suppose, there are two independent objects, Object A and Object B. Object B has 500 records. Can we create a master-details relationship in between these two objects.

Ans: No, can’t create directly.
First create a lookup relationship, then associate all the child with their parent. Then convert into the Master-Details Relationship.

7. Can a Standard object be a master of a custom object.

Ans: Yes.

8. Can a custom object be a master of a standard object.

Ans: No.

9. Which relationship is in between, Account+Contact, Account+Opportunity.

Ans: Account + Contact = Lookup Relationship. But as cascade delete option is enabled, so if we delete Account record, all the related contacts get deleted cascadingly. Account + Opportunity = Lookup Relationship. But as cascade delete option is enabled, so if we delete Account record, all the related contacts get deleted cascadingly.

10. What is Rollup Summary field.

Ans: It is a read only field, which is created on Master side and used to apply Aggregate functions (COUNT, SUM, MIN, MAX) over child record. Only supported in Master-Details Relationship.

11. Why AVG function is not available in Rollup Summary field aggregate functions.

Ans: We can achieve AVG function by create formula field (AVG = SUM/COUNT).

12. What is the governor limit of Rollup Summary field.

Ans: 25 per object.

13. Can we create a Rollup Summary field on Account for Contacts.

Ans: No.

14. Can we create a Rollup Summary field on Account for Opportunity.

Ans: Yes.

15. How can we make Parent field compulsory in the case of Lookup Relationship.

Ans: Go to lookup field on child side, and make field REQUIRED.

16. What is governor limits of Master-Details relationships.

Ans: 02 Per Object.

17. What is a Junction object.

Ans: A Junction Object in Salesforce is a custom object that establishes a many-to-many relationship between two other objects.

18.What is a self-Relationship.

Ans: A Self Relationship in Salesforce is a lookup relationship where an object has a relationship with itself. This allows records of the same object to be linked together. Account (Parent) -> Account (Child)

19. What is a Hierarchical Relationship.

Ans: When an object has lookup relationship with User object, then it is a Hierarchical Relationship.

20. What is the Dis-Advantages of Relationship.

Ans: Complexity: Relationships can add complexity to the data model, making it harder to understand and manage.
Data Integrity: Master-Detail relationships enforce strict data integrity, which can sometimes be restrictive. For example, child records can't exist without a parent record.
Performance: Complex relationships, especially many-to-many, can impact performance due to increased data processing and storage requirements.
Limitations: Salesforce imposes limits on the number of relationships per object (e.g., maximum number of master-detail relationships).
Maintenance: More relationships mean more maintenance, including updates to relationships when business requirements change.

21. What happens to the Detail (Child) record when a Master (Parent) record is deleted?

Ans: In a Master–Detail relationship, when a Master record is deleted, the Detail record also gets deleted, automatically. On the other hand, in a Lookup relationship, the Child record will not be deleted, even if the Parent record is deleted.

22. By default, we cannot change master record at details side. How to make this possible?

Ans: Reparenting. Select reparenting checkbox on mater-details relationship.

23. How to display Account Name and Rating in the Parent Lookup dialog of Contact. (If you go to the Contact record, select parent Account, then only Account Name will be displayed)

Ans: Create a formula field on Account 'Name and Rating' -> Concatenate Name+Rating.
Go to Object Manager -> Account Object -> Search Layout -> Default Layout -> Edit -> Add formula field 'Name and Rating'.

24. How will you create a many-to-many relationship?

Ans: A many-to-many relationship can be created by using a junction object. A Junction object is a custom object that has two Master–Detail relationships.

25. Consider, there are three object A, B and C, where A and B are parent object and object C is a junction object. Relationship in C object is master-details. If we delete A1 record from object A, what will happen?


Object Name A (Master 1) B (Master 2) C (Junction Object)
Records A1 B1 A1, B1
A2 B2 A2, B2

Ans: A1 record from object A will get deleted.
Record A1, B1 from junction object C will get deleted, Because, in C junction object, A1 is master record, and if master record deleted, then its child records also get deleted.
Here, there will be no any impact on B1 record of B object.

Object Name A (Master 1) B (Master 2) C (Junction Object)
Records - B1 -
A2 B2 A2, B2

26. Consider, there are three object A, B and C, where A and B are parent object and object C is a junction object . Relationship in C object is Lookup relationship. If we delete A1 record from object A, what will happen?


Object Name A (Parent 1) B (Parent 2) C (Junction Object)
Records A1 B1 A1, B1
A2 B2 A2, B2

Ans: A1 record from object A will get deleted and A1 field will get deleted from object C. No impact on B1 record of C object and B object.

Object Name A (Parent 1) B (Parent 2) C (Junction Object)
Records - B1 -   ,  B1
A2 B2 A2, B2