In Interview for the salesforce technology, one common question asked is how to implement the many to many relationship. If we answer that using junction object then there next question comes how ? explain it and after that, next question will be what happen if i delete one master record ?
So, in this article i will first show you that how to create custom objects, how to relate them and what will happen if we delete master or child?
here i am going to assume that we want to relate A and B. Let us assume that we have two custom object – A and B.
To provide the many to many relationship between A and B, we will need to create one more object let’s say it would be C, it will be called as junction object.
So, start with creating Object A.
In same way, as shown in above image create B and C. For the simplicity of the example i have not added any field in Object A and B. By default Name field is provided by the salesforce on all objects.
We are going to use the object C as a junction object for A and B.
on object C, create “first Master-Detail” field and select object A as parent. This will be Primary Master – Detail relationship.
In next screen give the name of the field.
for the Master record A, i have used name “ChildOfA” and in same way for the Master record B – i used “ChildOfB”.
Untill now, we have created two fields on object C in which one refer to master record A and other will refer master record B as shown in below screen. Now we can create a tab for all the custom objects to add the record. First create record for A then B and for record C screen will look like below snap.
Few important points (Interview Questions of salesforce ):
- One Object can have only two Master-Detail relationships.
- If we delete record A (First Master detail relationship is always primary) – then child record c will be deleted.
- If we delete record B then in this case also child record C will be deleted.
- If we delete record c then only C will be deleted , master record will not be deleted.
- If child C has two Master record A and B, Where A is primary relation then Child record C will inherit the look and feel of Parent object A.
Leave a Reply