function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Gaurav AgnihotriGaurav Agnihotri 

Master detail relationship

I am preparing for salesforce developer I certification and ran into a question:
 
A Developer wants to create a custom object to track Customer Invoices.
How should Invoices and Accounts be related to relate that all invoices are visible to everyone with access to the Account?
Of course it’s going to be a master detail relationship
There are two options:
The Invoice should have master detail relationship to the Account
 The Account should have master detail relationship to the Invoice.I want to know what is the difference between the two. They both look similar.
Can someone please help
Gaurav AgnihotriGaurav Agnihotri
Two options are 
  1. The Invoice should have master detail relationship to the Account
  2.  The Account should have master detail relationship to the Invoice.

Apologize they were not clear in the question

 
Tarun J.Tarun J.
Hello Gaurav,

Here Account is standard object. Standard Objects can always be on Master side. Hence, in your case, Account will be on Master side and Invoice will be on Detail side.

-Thanks,
TK
Gaurav AgnihotriGaurav Agnihotri
Of couse you create a master detail relationship onthe invoice  object and choose Account as parent. 
reymagdaongreymagdaong
1. The Invoice should have master detail relationship to the Account
 2. The Account should have master detail relationship to the Invoice.
I want to know what is the difference between the two. They both look similar.
Can someone please help


I think the correct answer on this is the 'The invoice should have master detail relationship to the Account', sine you need to create the relationship inside the invoice object.

As for the difference, option 1 means, that the account can have zero to many invoices. and you cannot have an invoice without an account existing.
option 2 means, that a single invoice can have zero to many accounts, which doesn't make sense for rerequirement.

hope this helps.  
 
Deepthi BDeepthi B
Hello Gaurav,
The Master Detail relationship can exist within Standard and Custom SObjects, but the Master should be the Standard Sobject. We cannot create a Standard Object as child to a Custom Sobject. This can happen with Lookup Relationship.
  • The Invoice should have master detail relationship to the Account --- The invoice(child) is related to Account(parent) stating that invoice couldnt be created without addressing the associated Account 
  • The Account should have master detail relationship to the Invoice --- This is not possible because it states like Account is having MD relationship to custom object. 
Hope this helps you!
Regards,
Deepthi
rahul Shukla 37rahul Shukla 37
There are two custom objects in the system. [A ] Invoice [B] Invoice Line Item. Invoive Line Item has master detail relationship with Invoice and Invoive has lookup relationship with opportunity. On opportunity object, we have a custom field called Invoived__c (Checkbox). If user is changing opportunity.invoiced__c to true thaen create Invoice and Invoice Line item using apex trgger. 
rahul Shukla 37rahul Shukla 37
Anyone can please help me to achieve this trigger
Suraj Tripathi 47Suraj Tripathi 47
Hi Gaurav,

Greetings!

In the first statement, It says the invoice object is a child of account and In the second statement, the account is the child of the invoice.
But you can not create an MD relationship in standard objects,
So it means the Account should be the parent and the invoice should be the child.
So create an MD relationship field in the invoice object.
Statement 1 is correct.

If you find your Solution then mark this as the best answer. 

Thank you!

Regards,
Suraj Tripathi