1

I a trying to create a service resource by putting resource type as Technician in a test class.

Like below:

List<Map<String, Object>> paramsList = new List<Map<String, Object>>();    
ServiceResource serviceResourceRecord 
                        = new ServiceResource(Name=ResourceName
                                           , ResourceType ='Technician'
                                           , RelatedRecordId=relatedUser.Id
                                           , IsActive=true);
insert serviceResourceRecord;

Getting below issue:

System.DmlException: Insert failed. First exception on row 0; first error: INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST, Resource Type: bad value for restricted picklist field: Technician: [ResourceType]

I tried checking allowed values in the pick list:

enter image description here

I am seeing Technician in the pick list of resource type:

enter image description here

How can I create Technician type resource through apex?

1
  • Can the same user create another record? Currently, its not allowing the same user to create another record with same resource type fetching error like "Error A technician master of this type already exists for this user. Select a different Resource Type or edit the existing technician master." Commented Oct 25 at 8:30

1 Answer 1

2

if you manually create a ServiceResource and then query it you will find that resourcetype is set as 'T' not as 'Technincian' hence you need to pass 'T'which is a valid value for this picklist.

ServiceResource serviceResourceRecord 
                        = new ServiceResource(Name='ResourceName2'
                                           , ResourceType ='T'
                                           , RelatedRecordId=relatedUser.Id
                                           , IsActive=true);
insert serviceResourceRecord;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .