+ 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.