+ Start a Discussion
Zabi MohammedZabi Mohammed 

First exception on row 0; first error: MANAGER_NOT_DEFINED, Manager undefined.: [] in test case for approval process

Hai,

  i have a problem with approval process test case that is First exception on row 0; first error: MANAGER_NOT_DEFINED, Manager undefined.: []
please help me on this.

Thanks and Regards,
  jabee
Zabi MohammedZabi Mohammed
Hi Amit,

   in approval process next approver to the records is Manager 

thanks,
  zabi
Amit Chaudhary 8Amit Chaudhary 8
So in Test class please create on user and set manager of that user and Use RunAs 
That will resolve your issue
@isTest
private class TestRunAs {
   public static testMethod void testRunAs() {
      // Setup test data
      // This code runs as the system user
      Profile p = [SELECT Id FROM Profile WHERE Name='Standard User']; 


User umgr = new User(Alias = 'mstandt', Email='manafer@testorg.com', EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', LocaleSidKey='en_US', ProfileId = p.Id, TimeZoneSidKey='America/Los_Angeles', UserName='
manafer@testorg.com');

insert umgr ;

      User u = new User(Alias = 'standt', Email='standarduser@testorg.com', 
      EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
      LocaleSidKey='en_US', ProfileId = p.Id, 
      TimeZoneSidKey='America/Los_Angeles', UserName='standarduser@testorg.com', managerid=umgr.id );

      System.runAs(u) {
         // The following code runs as user 'u' 
         System.debug('Current User: ' + UserInfo.getUserName());
         System.debug('Current Profile: ' + UserInfo.getProfileId()); 
      }
   }
}


Please let us know if this will help u
Zabi MohammedZabi Mohammed
Hai Amit,

  this code is not working for my test class,
   
  Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();        
 req.setComments('Approve.');         
req.setNextApproverIds(new Id[] {UserInfo.getUserId(),UserInfo.getUserId()});       
  req.setObjectId(objId);       
  Approval.ProcessResult result = Approval.process(req);

this is code i am using to cover the code using test class hear i am getting 

System.DmlException: Process failed. First exception on row 0; first error: MANAGER_NOT_DEFINED, Manager undefined.: []

thanks,
zabi

 
Mohammed zabi 6Mohammed zabi 6
Hi Zabi,

This Error comes because of in Approval procress number of Assigned Approver we should enter all the names.
Example: we have number of approvars 4 and Number of assigned Approver 5 then we should enter all the assigned approver i.e 5.

then your issue cone solved.

Thanks,
Mohammed.