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
Andy Freeston_LarterAndy Freeston_Larter 

Locking an Opportunity after it becomes Closed

Hi,

I am trying to find a way to lock an Opportunity and all child objects once the Opportunity is closed. I can restrict access by putting conditions on the standard buttons (to show an error message, etc), but a malicious user could bypass these. Also this does not protect detail objects, such as those from a 3rd party vendor.

I would like to force the restrictions using access rights, perhaps by setting them in a trigger as the Opportunity becomes closed. Ideally all users except Administrators should be denied access once the Opportunity has become closed.

Is this possible?

Many thanks.

-          Andy

Best Answer chosen by Admin (Salesforce Developers) 
Andy Freeston_LarterAndy Freeston_Larter

Thanks for the link Venkat.

 

The application itself isn't what I need but it does show that I can achieve my goals by using triggers. Something like this should do the trick:

 

trigger CheckOpportunityDeleteLock on Opportunity (before delete, before update) { // Perform a quick check to see if the current user and system need Opportunity locking if ( !MSO_CheckIfLocked.UserAndSystemRequireLocking() ) return; for ( Opportunity o : trigger.old ) { if ( o.isClosed ) { if ( Trigger.isUpdate ) trigger.newMap.get(o.Id).addError( 'ERROR: Cannot change an Opportunity after it has been closed.' ); else o.addError( 'ERROR: Cannot delete an Opportunity after it has been closed.' ); } } }

 

It's a shame the UI code in Record Lock requires S-Controls and can't (yet) be ported to Visualforce.

Message Edited by AndyLarter on 01-12-2010 07:00 AM

All Answers

Venkat PolisettVenkat Polisett

Try this:
 
Andy Freeston_LarterAndy Freeston_Larter

Thanks for the link Venkat.

 

The application itself isn't what I need but it does show that I can achieve my goals by using triggers. Something like this should do the trick:

 

trigger CheckOpportunityDeleteLock on Opportunity (before delete, before update) { // Perform a quick check to see if the current user and system need Opportunity locking if ( !MSO_CheckIfLocked.UserAndSystemRequireLocking() ) return; for ( Opportunity o : trigger.old ) { if ( o.isClosed ) { if ( Trigger.isUpdate ) trigger.newMap.get(o.Id).addError( 'ERROR: Cannot change an Opportunity after it has been closed.' ); else o.addError( 'ERROR: Cannot delete an Opportunity after it has been closed.' ); } } }

 

It's a shame the UI code in Record Lock requires S-Controls and can't (yet) be ported to Visualforce.

Message Edited by AndyLarter on 01-12-2010 07:00 AM
This was selected as the best answer