• Yao Lin
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
Hi, 

When a record is submitted for approval, it is locked by default. I created Apex class which unlocks the record submitted for approval on the custom object Sales Order. I already checked Enable record locking and unlocking in Apex in Process Automation setting. However, record is still locked after I submitted it. Can anyone please help?
public class UnlockSOApprovalProcess{

    public static void unlockSORecord(PBSI__PBSI_Sales_Order__c soRecord) {
        Approval.UnlockResult unlockedRersult = Approval.unlock(soRecord);
        // Iterate through each returned result
        if (unlockedRersult.isSuccess()) {
            // Operation was successful, so get the ID of the record that was processed
            System.debug('Successfully unlocked Sales Order with ID: ' + unlockedRersult.getId());
        }
        else {
            // Operation failed, so get all errors                
            for(Database.Error err : unlockedRersult.getErrors()) {
                System.debug('The following error has occurred.');                    
                System.debug(err.getStatusCode() + ': ' + err.getMessage());
                System.debug('opportunity fields that affected this error: ' + err.getFields());
            }
        }
       
        
    }   
}

 
Hi,

I need to unlock a record after it is submitted in an Approval Process for a custom object Sales Order. I tried Apex trigger, but it seems not working. Will I need an Apex Test for the trigger? If so, how can I write it? Please help!

​​​​​​
Trigger SOLockRecord on PBSI__PBSI_Sales_Order__c (after update) {

For (PBSI__PBSI_Sales_Order__c so: Trigger.New){
if(Approval.isLocked(so.Id)){
Approval.unlock(so.Id);
}}
    
}

 
Hi all,

I am not familiar with Visualforce page. Please help the following scenario: I need to display an alert on Sales Order when a Sales Orde Line with a specific item is created. Sales Order is a Master Object and Sales Order Line is a Detail Object. One Sales Order can have many Sales Order Lines. I tried the following code, but it didn't work. 
<apex:page standardController="PBSI__PBSI_Sales_Order__c">
  <script>

PBSI__PBSI_Sales_Order_Line__c record =(PBSI__PBSI_Sales_Order_Line__c)stdController.getRecord(); 

 List<PBSI__PBSI_Sales_Order_Line__c> SOL = [SELECT Id, PBSI__Sales_Order__c, PBSI__Item__c FROM PBSI__PBSI_Sales_Order_Line__c WHERE (PBSI__Sales_Order__c = :record.PBSI__PBSI_Sales_Order__c.Id AND PBSI__Item__c ='a0Xi0000002EqKu'];

                alert('Display Alert!!');
                
            
  </script>
</apex:page>

Thanks!

 
  • September 06, 2019
  • Like
  • 0
Hi, 

When a record is submitted for approval, it is locked by default. I created Apex class which unlocks the record submitted for approval on the custom object Sales Order. I already checked Enable record locking and unlocking in Apex in Process Automation setting. However, record is still locked after I submitted it. Can anyone please help?
public class UnlockSOApprovalProcess{

    public static void unlockSORecord(PBSI__PBSI_Sales_Order__c soRecord) {
        Approval.UnlockResult unlockedRersult = Approval.unlock(soRecord);
        // Iterate through each returned result
        if (unlockedRersult.isSuccess()) {
            // Operation was successful, so get the ID of the record that was processed
            System.debug('Successfully unlocked Sales Order with ID: ' + unlockedRersult.getId());
        }
        else {
            // Operation failed, so get all errors                
            for(Database.Error err : unlockedRersult.getErrors()) {
                System.debug('The following error has occurred.');                    
                System.debug(err.getStatusCode() + ': ' + err.getMessage());
                System.debug('opportunity fields that affected this error: ' + err.getFields());
            }
        }
       
        
    }   
}

 
Hi,

I need to unlock a record after it is submitted in an Approval Process for a custom object Sales Order. I tried Apex trigger, but it seems not working. Will I need an Apex Test for the trigger? If so, how can I write it? Please help!

​​​​​​
Trigger SOLockRecord on PBSI__PBSI_Sales_Order__c (after update) {

For (PBSI__PBSI_Sales_Order__c so: Trigger.New){
if(Approval.isLocked(so.Id)){
Approval.unlock(so.Id);
}}
    
}