+ Start a Discussion
CraigHCraigH 

Make an object & children read only based on status

Hi,

 

I have a custom object (say 'Project') that has various fields, has child base objects like notes/attachments, activities + has other child custom objects as master-detail relationships (i.e. issues, risks, etc).

 

One of the fields on the Project object is status (i.e. proposed, under work, completed).  

 

I would like it so that when a project status is set to completed, the project & all child objects are made read only.

 

I have tried using record types + making a different page layout that has its fields read only.  Using a workflow, I set the record type that uses this 'read only' page layout when the status is set to completed.  However this has issues in that:

 

-users can still change fields set as read only in the page layout by double-clicking 

-can't seem to not have the 'edit' link appear next to child object entries

-can't seem to hide the new note/attach button

 

Not to mention the added complexities of ensuring record types for each child object are correctly set based on the parent object status change.

 

One other approach I am considering is to use sharing rules:

 

-by default have the project object be private

-have a sharing rule that will grant access to all users in read/write (i.e. if the status of the project is not completed, anybody can read/edit)

 

-upon change of status to completed, have a trigger that will:

>change the owner to a 'admin user' (they will be the only one that can edit it)

>delete existing sharing rule

>add sharing rule to be read only for all users

 

 

I haven't tried to code this so not sure if this will work.

 

Does anybody have any other ideas on how this requirement can be met?

 

 

 

visulaforcevisulaforce
yes sharing rule will best approach
Rajesh ShahRajesh Shah

Hi,

 

If a field is defined as read only on page layout, the user should not be able to edit even by double clicking. Also even if the edit link is visible, it should not make a difference as all fields will be read only on the page layout. Also, you can remove the edit button from the read only page layout.

 

Regarding hiding New notes/Attachments, that is tough one. I can think of 2 options.

1. Write a trigger on notes and attachments that prevents the user from updating/deleting attachments/notes. The trigger can still not prevent the user from inserting

 

2. Override the view page with a VF page. Use detail tag to display the detail and related list tag for other related lists. For notes and attachments, based on the status, you can decide whether to display using related list or make your own using pageBlockTable not having any buttons.

 

 

CraigHCraigH

Hi

 

Yes you are right about the double clicking - I was testing it out using an admin id which had the override to allow any editing of data.

 

I'm leaning towards going the sharing rules route.  Although its not as nice from a UI point of view since the user can still enter in new data and they just get an error upon trying to save it, its less work than having to write custom VF components for each child object + new page layouts and having the layouts correctly set for the main + child objects.