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
daniel.duartedaniel.duarte 

Record Types and Master-Detail Relationship

Hello,

Does the Record Type of my custom object affect the objects that are a detail of this object in a master-detail relationship?

For example, I have a ParentObject__c and a ChildObject__c, and in the child object I create a custom master-detail relationship field that references the parent object. Then, I create different record types for the parent object. Can I display different page layouts for the child object according to its parent type?

Another question: can I have a custom field that is required for one record type but not required for another?

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
Ritesh AswaneyRitesh Aswaney
Record types are object specific, you can't have child page layouts based on the parent record type.

You can have page layouts corresponding to your different record types, and then on page layout for the record type which requires the field to be mandatory, you can set the page layout level required checkbox on the field.

All Answers

Ritesh AswaneyRitesh Aswaney
Record types are object specific, you can't have child page layouts based on the parent record type.

You can have page layouts corresponding to your different record types, and then on page layout for the record type which requires the field to be mandatory, you can set the page layout level required checkbox on the field.
This was selected as the best answer
daniel.duartedaniel.duarte

Thanks.

I needed to display different page layouts at the moment that I create the record, depending on the parent's type. So I won´t be able to do this using record types, correct? I will have to customize the creation/edition page for the record and show or hide specif fields depending on the parent record type.

daniel.duartedaniel.duarte

Can I do something like automatically set the record type for the child record before inserting it? Is there anyway to show a different page for new records avoiding apex code and using SF standard resources, like Record Types or something similar?

Ritesh AswaneyRitesh Aswaney
There is a way I suspect, albeit twisted
Have a formula field on the parent called ChildRecordType, which is populated with the desired ChildRecordTypeid based on the parent record type, add this to the layout,
Create a custom button on the child object to override the default new button. Grab the default new button URL and set as the URL of this button. Save for replace the recordtype=Xxxxx part with the formula field we created above. Sort of like URL rewriting/ screen scraping . Set to recordtype={!ChildRecordTypeId} in the URL.
Add this button in the related list in the parent page layout. Needless to say this will work only when child records are created from the parent screen. You might want to hide the child tab to prevent creation via the default route.

Then there is always an apex trigger. You could have a before insert trigger on the child which sets the appropriate record type based on the parent record type,
daniel.duartedaniel.duarte

I am using different layout configuration, with different required fields in each. The only inconvenient is that the user has to choose which record type does he want before showing the creation page. I was trying to find an easy way to avoid it using master-detail relationship, defining the record type according to the master.

Carine BRESCarine BRES
Hi Ritesh Aswaney, many years later, your last comment really helped me (create a custom button) ! Thank you !