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
JaiJai 

Please help me on the below error for test class

when i am running my test method i am geting the below error:

System.DmlException: Process failed. First exception on row 0; first error: MANAGER_NOT_DEFINED, This approval request requires the next approver to be determined by the Manager field. This value is empty. Please contact your administrator for more information.: []

Apex class:
-------------
Public static void IncentiveCompAutoSubmitApproval(List<Case> tickets)
   {
       try{
       Map<ID, RecordType> recordTypeMap = New Map<ID, RecordType>([Select ID, Name From RecordType Where sObjectType = 'Case']);
       set<Id> ticketId = new set<Id>();
       Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
       for(Case cs : tickets)
       {  if(recordTypeMap.get(cs.recordTypeID).name.containsIgnoreCase('Incentive Compensation Request')&& cs.Status =='open'&& cs.managerid__c != null)
          {
              req1.setComments('Submitting request for approval.');
              req1.setObjectId(cs.Id);
              req1.setSubmitterId(UserInfo.getUserId());
              req1.setProcessDefinitionNameOrId('Incentive_Compensation_Tier_1_Approvals');
              req1.setSkipEntryCriteria(true);
                  system.debug('test111 ' + cs.managerid__c);
             Approval.ProcessResult result = Approval.process(req1);
              system.debug('test222 ' + cs.managerid__c);
          }    
       }
       }catch(QueryException qe){
            system.debug('QueryException: '+qe);
        }
            catch(Exception e){
                System.debug('Exception caught: ' + e.getMessage());
            }
   }

Test Method
------------------
@isTest static void IncentiveCompAutoSubmitApprovalTest()
    {
        Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator']; 
      Userrole objr = [SELECT Id FROM UserRole WHERE Name = 'Global Administrator' LIMIT 1];
       User thisUser = new User(Alias = 'standt', Email='contractdesk@testorg.com', 
                                 EmailEncodingKey='UTF-8', LastName='contractdesk', LanguageLocaleKey='en_US', 
                                 LocaleSidKey='en_US', ProfileId = p.Id,UserRoleId = objr.Id,
                                 TimeZoneSidKey='America/Los_Angeles', UserName='contractdesk@testorg.com');
        TestDataBuilder testBuilder = new TestDataBuilder();
        //insert manager
        User usrManager             = new User();
        usrManager          = testBuilder.dummyUser(0);
        usrManager.UserRoleId = objr.Id;
        insert usrManager; 
        //Insert User
        User usr                = new User();
        usr             = testBuilder.dummyUser(1);
        usr.ManagerId   = usrManager.Id;
        usr.UserRoleId = objr.Id;
        
        insert usr;
      
      System.runAs(thisUser){
      List<case> caseList = new List<case>();
        //insert Case
        Case cse                    = new Case();
        cse.RecordTypeId    = eUiteroRecordTypeId1;
        cse.Status='Open';
        cse.Type_of_Credit__c='Internal';
        cse.Reason_for_Credit__c='Staff Discount Coupon';
        cse.Order_Type__c='invisalign';
        cse.Subject='Testing';
        cse.Invoice_Number__c='1234567891';
        cse.Amount_of_credit__c=10;
        cse.Order_type__c='webstore';
        cse.Sales_Order_Number__c='123456';
        //cse.managerid__c = usr.ManagerId;
      insert cse;
       Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
          req1.setComments('Submitting request for approval.');
              req1.setObjectId(cse.Id);
              req1.setSubmitterId(UserInfo.getUserId());
              req1.setProcessDefinitionNameOrId('Incentive_Compensation_Tier_1_Approvals');
                req1.setNextApproverIds(new Id[] {usr.ManagerId});
              req1.setSkipEntryCriteria(true);
          
          Approval.ProcessResult result1 = Approval.process(req1);
    }
    }

Thanks!!
Shiraz HodaShiraz Hoda
Hi Jai,

Change this line of code. This will solve your problem.
 
req1.setSubmitterId(usr.Id);