+ Start a Discussion
Hemant ReddyHemant Reddy 

Apex - Allow record creation who has edit access on parent record

I have a below requirement. Please suggest the best option to implement it .

Allow the user to create opportunity related record if the user has edit access on the opportunity. If user doesn't have edit access on opprtunity and tries to create the related record (e.g : Custom Object record ) throw the user friendly error message . 
Marcos LasoMarcos Laso
If your not in a master-detail relationship, you could write a trigger on related record that queries UserRecordAccess table (more info) (https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_userrecordaccess.htm) . It these records you can find which is the current user access level to the record (your parent opportunity in your case) and its no edit use addError() to show a friendly error message.

Hope it helps!