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
subramanyam Rsubramanyam R 

how to write a trigger for Converting Lookup field to Master-Detail Relationship or Master-Detail Relationship to Lookup field

Shashikant SharmaShashikant Sharma
Do you want to change meta-data to change field data type ? Share more details about the issue.
Always ThinkinAlways Thinkin
Since those are two different types of metadata field, you cannot convert the field itself in a trigger. As @shashikant sharma implies, you would have to change the field type itself to the one you want. Both types take the same value, a record ID, but the behavior is different. If you have both fields present on the object, you can simply pass the ID from one to the other however it would make for an odd data schema. You're probably better off going with the Master-Detail Relationship because of the work involved in replicating its functionality in Apex, and you can reduce the requirements and behaviors in the configuration of the Master-Detail field.