+ Start a Discussion
doubleminusdoubleminus 

How to lock a layout section using Apex

I want to lock all of the fields within a layout section if a picklist value is selected.

So for example, if you choose a picklist value "Purchased" instead of "Leased"...the "Lease Information" layout section becomes locked or otherwise uneditable.  Is this possible?  Any hints on the best way to go about this?

I mean I know it should just be a basic IF THEN statment  "IF acquisition_type__c == Leased THEN ..."

Not sure how to put this into Apex, or what the best approach is, for locking an entire section.  Or is there no way to lock an entire section in one foul swoop?

Thank you.

Nate
werewolfwerewolf
You can't do this in Apex, which only gets run when the page is saved -- you can do it with a Visualforce page though.
doubleminusdoubleminus
Makes sense, should have thought of that.

So could I use some Apex to have it make that section invisible upon save?  So if you choose "Purchased" and hit Save...that Lease Info section disappears?  (or it can lock too, or otherwise become inaccessible).
werewolfwerewolf
Actually you might think about using workflow, record types and page layouts to do that.  Like say you choose Purchased, then you change the object to the Purchased record type (using a workflow rule) which makes it display using the Purchased layout which makes all the relevant fields read-only.  Code should be the last resort...
doubleminusdoubleminus
We are already pretty deep into our project which already contains a mess of record types and such.  I'm now trying to put some finishing touches on the first phase, while simultaneously beginning to learn Apex.
werewolfwerewolf
Well, there's nothing you can do in Apex (besides changing the record type) to change how fields are shown -- to do that you have to write a Visualforce page.