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
big bangbig bang 

Is there any way to restrict who can't access a specific Attachment even he can modify the parent record?

Hi...
I have a custom object, in which there are two kind of infomation, Customers and Cars.
User A creates a record and input the Customer's info, user B modify it then input the Car's info, user B cannot see what user A inputted.(this can be done by set the Field Level Access)

But, how about the attachment?
User A would upload some files into Attachment relative to the Customer, this is secret to user B, vice versa B may upload some photos about the car which A should not see it.

How to deal with this case? Any ideas?

Thank you.
BALAJI CHBALAJI CH
Hi,

You can write a small trigger to set the Attachments of your custom Object to "IsPrivate" to true so that the attachments and notes marked as Private, are only viewable by an administrator or the person that added the attachments or notes.
Please find below Sample Trigger as per the requirement.
trigger AttachmentPrivate on Attachment (before insert) {
    for(Attachment record:Trigger.new) 
    {
        if((String.valueOf(reocrd.parentId)).startswith('XXX')) //xxx would be your custom object prefix like 001 for Account.
            record.IsPrivate = TRUE;
    }
}

Let us know if that helps you.

Best Regards,
BALAJI