{"id":2473,"date":"2011-10-20T14:25:23","date_gmt":"2011-10-20T08:55:23","guid":{"rendered":"http:\/\/JitendraZaa.com\/blog\/?p=2473"},"modified":"2011-10-20T14:25:23","modified_gmt":"2011-10-20T08:55:23","slug":"deep-drive-in-junction-object-create-many-to-many-relationship-in-salesforce","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/deep-drive-in-junction-object-create-many-to-many-relationship-in-salesforce\/","title":{"rendered":"Deep  dive into Junction object &#8211; Create many to many relationship in Salesforce"},"content":{"rendered":"<p>In Interview for the salesforce technology, one common question asked is how to implement the many to many relationship. If we answer that using<strong> junction object<\/strong> then there next question comes how ? explain it and after that, next question will be what happen if i delete one master record ?<\/p>\n<p>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?<\/p>\n<p>here i am going to assume that we want to relate <strong>A <\/strong>and <strong>B. <\/strong>Let us assume that we have two custom object &#8211;<strong> A<\/strong> and <strong>B<\/strong>.<\/p>\n<p>To provide the many to many relationship between A and B, we will need to create one more object let&#8217;s say it would be <strong>C<\/strong>, it will be called as <strong>junction object<\/strong>.<\/p>\n<p>So, start with creating Object A.<\/p>\n<figure id=\"attachment_2475\" aria-describedby=\"caption-attachment-2475\" style=\"width: 421px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/10\/Creating-Custom-object-in-salesforce.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2475 \" title=\"Creating Custom object in salesforce\" src=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/10\/Creating-Custom-object-in-salesforce.png?resize=421%2C365&#038;ssl=1\" alt=\"Creating Custom object in salesforce\" width=\"421\" height=\"365\" \/><\/a><figcaption id=\"caption-attachment-2475\" class=\"wp-caption-text\">Creating Custom object in salesforce<\/figcaption><\/figure>\n<p><!--more-->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.<\/p>\n<p>We are going to use the object <strong>C as a junction object <\/strong>for A and B.<\/p>\n<p>on object C, create &#8220;first Master-Detail&#8221; field and select object A as parent. This will be <strong>Primary Master &#8211; Detail relationship.<\/strong><\/p>\n<figure id=\"attachment_2476\" aria-describedby=\"caption-attachment-2476\" style=\"width: 449px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/10\/Salesforce-Master-Detail-relationship-select-Master-object.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2476\" title=\"Salesforce Master-Detail relationship - select Master object\" src=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/10\/Salesforce-Master-Detail-relationship-select-Master-object.png?resize=449%2C283&#038;ssl=1\" alt=\"Salesforce Master-Detail relationship - select Master object\" width=\"449\" height=\"283\" \/><\/a><figcaption id=\"caption-attachment-2476\" class=\"wp-caption-text\">Salesforce Master-Detail relationship - select Master object<\/figcaption><\/figure>\n<p>In next screen give the name of the field.<\/p>\n<figure id=\"attachment_2477\" aria-describedby=\"caption-attachment-2477\" style=\"width: 482px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/10\/Salesforce-Master-Detail-relationship-Give-the-field-Name.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2477 \" title=\"Salesforce Master-Detail relationship - Give the field Name\" src=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/10\/Salesforce-Master-Detail-relationship-Give-the-field-Name.png?resize=482%2C256&#038;ssl=1\" alt=\"Salesforce Master-Detail relationship - Give the field Name\" width=\"482\" height=\"256\" \/><\/a><figcaption id=\"caption-attachment-2477\" class=\"wp-caption-text\">Salesforce Master-Detail relationship - Give the field Name<\/figcaption><\/figure>\n<p>for the Master record A, i have used name &#8220;ChildOfA&#8221; and in same way for the Master record B &#8211; i used &#8220;ChildOfB&#8221;.<\/p>\n<p>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 <strong>A <\/strong>then <strong>B <\/strong>and for record <strong>C <\/strong>screen will look like below snap.<\/p>\n<figure id=\"attachment_2478\" aria-describedby=\"caption-attachment-2478\" style=\"width: 482px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/10\/Salesforce-Master-Detail-relationship-Many-to-Many-Relationship.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2478 \" title=\"Salesforce Master-Detail relationship - Many to Many Relationship\" src=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/10\/Salesforce-Master-Detail-relationship-Many-to-Many-Relationship.png?resize=482%2C228&#038;ssl=1\" alt=\"Salesforce Master-Detail relationship - Many to Many Relationship\" width=\"482\" height=\"228\" \/><\/a><figcaption id=\"caption-attachment-2478\" class=\"wp-caption-text\">Salesforce Master-Detail relationship - Many to Many Relationship<\/figcaption><\/figure>\n<p><strong>Few important points (Interview Questions of salesforce ):<\/strong><\/p>\n<ol>\n<li>One Object can have <strong>only two Master-Detail relationships<\/strong>.<\/li>\n<li>If we <strong>delete record A<\/strong> (First Master detail relationship is always primary) \u00a0\u2013 then child record c will be deleted.<\/li>\n<li>If we<strong> delete record B<\/strong> then in this case also child record C will be deleted.<\/li>\n<li>If we <strong>delete record c<\/strong> then only C will be deleted , master record will not be deleted.<\/li>\n<li>If child C has two Master record A and B, Where A is primary relation then <strong>Child record C will inherit the look and feel of Parent object A.<\/strong><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Article to show step by step process of creating junction object for Many to Many relationship in salesforce and impact of deleting one master record on others<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"jz_research_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[9],"tags":[331],"class_list":["post-2473","post","type-post","status-publish","format-standard","hentry","category-salesforce","tag-salesforce"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":1032,"url":"https:\/\/www.jitendrazaa.com\/blog\/others\/tips\/difference-in-master-detail-relationship-and-look-up-relationship-salesforce-interview-question\/","url_meta":{"origin":2473,"position":0},"title":"Difference in Master-Detail relationship and look up relationship &#8211; Salesforce Interview question","author":"Jitendra","date":"September 11, 2010","format":false,"excerpt":"Difference in Master-Detail relationship and look up relationship - Salesforce Interview question","rel":"","context":"In &quot;Tech Tips&quot;","block_context":{"text":"Tech Tips","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/others\/tips\/"},"img":{"alt_text":"Master detail and look up relationship Salesforce","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2010\/09\/Master-detail-and-look-up-relationship-Salesforce.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1038,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-interview-questions-part-2\/","url_meta":{"origin":2473,"position":1},"title":"Salesforce Interview Questions \u2013 Part 2","author":"Jitendra","date":"September 11, 2010","format":false,"excerpt":"Interview questions of salesforce.com, interview questions of visualforce.com and APEX","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Account Child relationship in salesforce","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2010\/09\/Account-Child-relationship-in-salesforce.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":2825,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/salesforce-interview-questions-part-7\/","url_meta":{"origin":2473,"position":2},"title":"Salesforce Interview Questions &#8211; Part 7","author":"Jitendra","date":"April 23, 2012","format":false,"excerpt":"Basic concepts and Interview Questions of salesforce, Visualforce, Apex and SOQL","rel":"","context":"In &quot;Apex&quot;","block_context":{"text":"Apex","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/apex\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1253,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/where-are-the-reports-for-my-custom-object-with-related-objects-in-salesforce\/","url_meta":{"origin":2473,"position":3},"title":"Where are the reports for my custom object with related objects in salesforce?","author":"Jitendra","date":"May 22, 2011","format":false,"excerpt":"Where are the reports for my custom object with related objects in salesforce?","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Report of custom object with related object in Salesforce","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/05\/Report-of-custom-object-with-related-object-in-Salesforce.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1192,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/step-by-step-salesforce-tutorial-creating-custom-object-1-of-n\/","url_meta":{"origin":2473,"position":4},"title":"Step by Step Salesforce Tutorial \u2013 Creating custom object \u2013 1 of 6","author":"Jitendra","date":"October 6, 2010","format":false,"excerpt":"Step by Step Salesforce Tutorial - Creating custom object - 1 of n tutorial series","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Create Custom object Eclipse Salesforce","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2010\/10\/Create-Custom-object-Eclipse-Salesforce-300x290.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1210,"url":"https:\/\/www.jitendrazaa.com\/blog\/salesforce\/roll-up-summary-fields-in-salesforce\/","url_meta":{"origin":2473,"position":5},"title":"Roll up Summary fields in Salesforce","author":"Jitendra","date":"October 11, 2010","format":false,"excerpt":"What is Roll up summary field in salesforce, what are the types of roll up summary field and how does it works","rel":"","context":"In &quot;Salesforce&quot;","block_context":{"text":"Salesforce","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/salesforce\/"},"img":{"alt_text":"Salesforce Rollup Summary field","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2010\/10\/Salesforce-Rollup-Summary.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/2473","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/comments?post=2473"}],"version-history":[{"count":0,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/2473\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=2473"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=2473"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=2473"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}