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
Anonymous DeveloperAnonymous Developer 

Need Help on this Test Class

Here's my code:
 
public class AS_UnlockProgramEngagement {
    @InvocableMethod (label = 'Unlock Program Engagement Record'
                      description = 'Unlock Program Engagement Object'
                      category = 'Program Engagement')
    public static void unlockProgramEngagementRecord (){
        List<pmdm__ProgramEngagement__c> brokerageList = [SELECT Id FROM pmdm__ProgramEngagement__c LIMIT 10]; // Get records to unlock
        List<pmdm__ProgramEngagement__c> lockList = new List <pmdm__ProgramEngagement__c>(); // Check locked records
        for(pmdm__ProgramEngagement__c b: brokerageList){
            if(Approval.isLocked(b.id)){
                lockList.add(b);
            }
        }
        if(!lockList.isEmpty()){ // Unlocks Record
            List<Approval.UnlockResult> unlockResultList = Approval.unlock(lockList, false);
            for(Approval.UnlockResult unlockResult : unlockResultList){
                if(unlockResult.isSuccess()){ // Get processed Id of the record
                    system.debug('Successfuly unlocked Brokerage Request' + unlockResult.getId());
                }
                else
                { 
                    for(Database.Error err : unlockResult.getErrors()){ // Get all errors
                        System.debug('The following error has occured.');
                        System.debug(err.getStatusCode() +' : ' + err.getMessage());
                        System.debug('Brokerage Request field that affected this error: ' +err.getFields());
                        // System.debug('Total Quotes Unlocked in the Execution : ' + unlockResultList.size());
                    }         
                }
            }
        }
    }
}


Thanks.
 
Best Answer chosen by Anonymous Developer
AnkaiahAnkaiah (Salesforce Developers) 
Hi,

try with below code.
 
@isTest
public class AS_UnlockProgramEngagementTest
{
    @isTest
    public static void AS_UnlockProgramTestMethod()
    {
        
     //insert the mandatory fields   
        pmdm__ProgramEngagement__c pmd = new pmdm__ProgramEngagement__c();
        pmd.Name = 'Test Opp';
        insert pmd;

AS_UnlockProgramEngagement.unlockProgramEngagementRecord();

    }
	
}

If this helps, Please mark it as best answer.

Thanks!!
 

All Answers

AnkaiahAnkaiah (Salesforce Developers) 
Hi,

try with below code.
 
@isTest
public class AS_UnlockProgramEngagementTest
{
    @isTest
    public static void AS_UnlockProgramTestMethod()
    {
        
     //insert the mandatory fields   
        pmdm__ProgramEngagement__c pmd = new pmdm__ProgramEngagement__c();
        pmd.Name = 'Test Opp';
        insert pmd;

AS_UnlockProgramEngagement.unlockProgramEngagementRecord();

    }
	
}

If this helps, Please mark it as best answer.

Thanks!!
 
This was selected as the best answer
Anonymous DeveloperAnonymous Developer

Hello Ankaiah

 

there is an error in the code

Class.AS_UnlockProgramEngagementTest.AS_UnlockProgramTestMethod: line 14, column 1