I have an object which has a master detail relationship with Account object. I want when creating a new record for this new object from the Account related list, to suggest the current account and not giving the ability to the user to change the record. How can this be applied ?
As in the screenshot below, i want the user not to be able to erase this account and select another one. I want it to be the same as in "Edit" action, read only. How can this be achieved?
-
I dont thinkwe can achieve this when we are creating a new record. We might need a custom solution.– Tushar SharmaAug 26, 2020 at 9:59
1 Answer
Solution1 - Change Master detail to Lookup
Just make it readonly for the desired profile from Field level security of the field (You will need to change your master-detail to Lookup)
- Goto the child object,
- Select the Lookup field (e.g. Account) .
- Select the Field level security and then make it read-only for the desired user profile.
Note: The above will work for non System Administrator profiles only, as they have power to unlock readonly fields.
Deleting children
In order to delete the related children, implement a trigger on Account before delete
handler.
Solution2 - Create Custom Component
You can create a VF page or Lightning component that will only have Label/display field that will display the account name and then you can drop on the page layout.
-
Hi Mahmood and thanks for your answer. However, Salesforce does not let me make the field read only from the Field Level Security. Aug 26, 2020 at 9:52
-
-
Despite the fact that i made it read only, it still gives me the ability to change the parent record. Also, i need it to be a master-detail cause whenever an account is deleted, i want to also make the child records get deleted. Aug 26, 2020 at 10:28
-
Remember that system admins can edit fields that are marked read-only via the page layout.– JimGAug 26, 2020 at 11:29
-
Ok, forgot to remove the "Edit read only fields" permission. So with lookup, my problem is solved. What about master-detail relationships? Can this be achieved with master-detail ? Aug 26, 2020 at 12:05