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
Terence VibanTerence Viban 

Why is the DelegatedApproverId's reference type "Group"

Hi all,

now this is an interesting one. I am working on a test data factory which automates the creation of test data. While creating a User, the factory is trying to create the Delegated Approver as well. I get this error 

 System.DmlException: Insert failed. First exception on row 0; first error: INVALID_TYPE, You can't assign a group or queue as a delegated approver. Select a valid user instead.: [DelegatedApproverId]

The reason for this is apparent when I look at what my factory is doing. The DelegatedApproverId is of type Reference and the reference and I would expect this reference type to be User. But it is Group and I guess tht is why I get this error. Here is a snippet from my debug log

11:06:54.90 (207722531)|USER_DEBUG|[113]|DEBUG|@@@@ buildSObject fName : DelegatedApproverId
11:06:54.90 (207934427)|USER_DEBUG|[116]|DEBUG|@@@@ buildSObject field.getName() : DelegatedApproverId
11:06:54.90 (207988984)|USER_DEBUG|[117]|DEBUG|@@@@ buildSObject field.getType().name() : REFERENCE
11:06:54.90 (208020802)|USER_DEBUG|[118]|DEBUG|@@@@ buildSObject field.isNillable : true
11:06:54.90 (208057314)|USER_DEBUG|[120]|DEBUG|@@@@ buildSObject compoundField : user_delegatedapproverid
11:06:54.90 (208284455)|USER_DEBUG|[226]|DEBUG|================================== REFERENCE (REFERENCE) ===================================
11:06:54.90 (208480665)|USER_DEBUG|[228]|DEBUG|@@@@ buildSObject referenceType : Group
11:06:54.90 (208513637)|USER_DEBUG|[229]|DEBUG|@@@@ buildSObject referenceType fieldNameValuePairs : {LastName=Viban}
11:06:54.90 (208527259)|USER_DEBUG|[230]|DEBUG|@@@@ buildSObject referenceType field.getName() : DelegatedApproverId
11:06:54.90 (208564003)|USER_DEBUG|[243]|DEBUG|@@@@ buildSObject referenceType objNameReferenceNameIdPairs : {}
11:06:54.90 (208574814)|USER_DEBUG|[244]|DEBUG|@@@@ buildSObject referenceType objName : User
11:06:54.90 (208621486)|USER_DEBUG|[264]|DEBUG|@@@@ buildSObject referenceType field.getName() inner : DelegatedApproverId
11:06:54.90 (208631891)|USER_DEBUG|[265]|DEBUG|@@@@ buildSObject referenceType inner : Group
11:06:54.90 (208698739)|USER_DEBUG|[83]|DEBUG|@@@@ createSObject objectName : Group
11:06:54.90 (208714328)|USER_DEBUG|[68]|DEBUG|@@@@ init objectName : Group

Does anyone know why the reference Tye for DelegatedApproverId is Group when I apparently have to supply a UserId??