Pages

Showing posts with label Approval Process. Show all posts
Showing posts with label Approval Process. Show all posts

Sunday, January 22, 2017

Salesforce: Auto Lock Record

Use case: make opportunity become read-only when opportunity reach stage Closed Won.

Options: there are multiple solutions for this, from simple to advance with code:

1. Record Type & Page Layout
This would be one of the most famous solution without code, but this will make the system more difficult to maintain as the object will have additional record type set and additional page layouts. In short, when the opportunity reach Closed Won, with Workflow, change the record type to new record type and assign the new record type with page layout with read-only fields.

2. Record Ownership
This will work by change the record owner to a system user in highest role hierarchy. This will work well when the OWD sharing setting is Public Read-Only. But, often this solution will not work well, because the original record owner changed and it is important for reporting, although you can create custom user field to store it.

3. Validation Rule
By using function PRIORVALUE() and ISCHANGED() to detect any changes happened in Closed Won record. User will get error when save opportunity has been marked as Closed Won previously.

4. Trigger
Since Winter '16, Salesforce introduce lock() and unlock() methods in the System.Approval namespace.  Admin need to enable this feature, from Setup | CreateWorkflow & Approvals | Process Automation Settings. Then, select Enable record locking and unlocking in Apex.

Example:
 // Query the opportunities to lock  
 Opportunity[] opty = [SELECT Id from Opportunity WHERE Name LIKE 'Acme%'];  
 // Lock the opportunities  
 Approval.LockResult[] lrList = Approval.lock(opty, false);  
 // Iterate through each returned result  
 for(Approval.LockResult lr : lrList) {  
   if (lr.isSuccess()) {  
     // Operation was successful, so get the ID of the record that was processed  
     System.debug('Successfully locked opportunity with ID: ' + lr.getId());  
   }  
   else {  
     // Operation failed, so get all errors          
     for(Database.Error err : lr.getErrors()) {  
       System.debug('The following error has occurred.');            
       System.debug(err.getStatusCode() + ': ' + err.getMessage());  
       System.debug('Opportunity fields that affected this error: ' + err.getFields());  
     }  
   }  
 }  

5. Process Builder and Approval Process
In previous blog, we shared about users able to edit locked record and who will see Unlock Record button. As Process Builder able to call Approval Process, we'll make use of this combination to auto submit for approval when opportunity reach Closed Won. The approval process here would be auto approve, therefore it will leave a trace in the approval process.

a). Create Approval Process

b). Create Process Builder

Drawback for option (5): opportunity approval history will show action for approval submitted and approved, this is not ideal if you use opportunity with other approval process.



Reference:


Sunday, July 6, 2014

Salesforce: Unlock Record button

Few months ago, I wrote a blog about who able to Edit Locked Record in Salesforce. Record owner and standard user would not able to edit the record, it will show a pad lock icon next to Edit button. When user click Edit button, the user will get error message Record Locked, The record you are trying to edit has been locked. Please contact your administrator if access is necessary.



Until now (July 2014), record locking mechanism in Salesforce only can be initiate from Approval Process. Some users will see Unlock Record button next to Edit button. Clicking that button will unlock the record, and the record become editable by record owner and standard users.



Compare with screenshot below when view by record owner or other user as below.



So, who will see the Unlock Record button and able to unlock the record:
1. User with System Administrator profile
2. User with Modify All Data permission
3. User with Modify All permission in the object locked

Once a record is unlock:
1. Pad lock icon will be disappear
2. Record owner or users with ability to edit the record will able to edit the record
3. In the object history, it will show date/time, user with action 'Record unlocked.'


4. The approval process for the record still in place, approver still able approve or reject the record.




ReferenceEdit Locked Record



Sunday, February 23, 2014

Salesforce: Edit Locked Record

In Approval Process, when a user click "Submit for Approval" or auto submit by Process Builder, record will be locked by default. This will prevent user to edit any fields in the record from page layout, notice a pad lock icon at the left of the buttons, even when you try to update via API tool, you will get error "The Entity Is Locked For Editing".

So, is there any user able to edit the record? YES, they are:
1. User with System Administrator profile
2. User with Modify All Data permission
3. User with Modify All permission in the object of record locked
4. If the Approval Process configuration in Record Editability Properties = Administrators OR the currently assigned approver can edit records during the approval process. This will allow current approver ability to edit the record.


Note: user does not fall into any of categorization above will NOT able to edit the record, including:
  • Record owner
  • User in higher role hierarchy of record owner
  • User in higher role hierarchy of approver
  • Delegated approver of the approver


Page-level ad