+ Start a Discussion
BarryPlumBarryPlum 

Determine if a record is "locked" in an approval process

We want to have all opportunities that are processed by sales operations become locked so that they cannot be moved around except by Admins.

The approval process works fine for that, but I've discovered that while they can't directly change ownership of the opportunity, if they transfer ownership of the Account AND they are the owner of the locked opportunity AND check the Transfer closed opportunities checkbox on the account transfer gui, it will actually transfer the locked opportunities.  Salesforce.com support says this is a "feature."

I figure the only way to fix this "feature" is to write a 'before update' trigger on opportunity to check if the opportunity is locked and if it is, roll back any changes being made to it unless you are an administrator (which kind of sounds like what locking is supposed to do, but hey, who am I to judge).

My question (finally) is: how do I determine that the record is actually locked? 

There are a couple of child relationships (ProcessInstances and ProcessSteps)  that appear to be related, but niether of them have a field that says anything about Locked or IsLocked, there is an IsPending in ProcessSteps, but if it is no longer pending, but still locked, that field will not be useful.

I could probably add yet another field to my object and have the approval process update that field to say that it's locked, but that just seems silly, as there has to be some way to determine whether the record is or is not locked.

Thanks,
Barry
dansanphadansanpha

Hi,

 

If History is enabled on the object, then you can query the object and know the latest lock or unlock action.

 

or else may be try to do an update action wrapped around appropriate catch block to know if it is going through(better save the Database point and restore it back). This will not work if running in system context.