1

I'm at a loss. This class already compiled, was deployed, and has been working fine in production for over a year. Upon updating it, I'm now getting:

HttpPut methods do not support parameter type of MyUserDefinedType

The @HttpPut method in the existing production code is:

@HttpPut
global static void activateContact(MyUserDefinedType user) {
    MyServiceClass service = new MyServiceClass( new List<MyUserDefinedType>{ user } );
    service.activateContacts();
}

I updated it to:

@HttpPut
global static void activateContact(MyUserDefinedType user) {
    MyServiceClass service = new MyServiceClass( new List<MyUserDefinedType>{ user } );

    try {
        service.activateContacts();
    }
    catch(MyUserDefinedType.MyUserException e) {
        RestContext.response.statusCode = 400;
        RestContext.response.responseBody = Blob.valueOf(e.getMessage());
    }
}

The changes to MyUserDefinedType were to add a method to validate the parameter values and I added the inner exception class MyUserException (which is thrown in the validation method). I tried removing the inner exception class to a top-level class, but that didn't change anything.

I don't know what would be causing it to suddenly be an invalid user-defined type for an Http Put annotation.

EDIT:

Turns out, I had added another User-Defined Type as a member variable of MyUserDefinedType, which isn't allowed within an HttpPut parameter. I resolved the issue by making it transient.

1 Answer 1

2

Per the Apex REST documentation you are restricted to certain types of parameter values:

These return and parameter types are allowed:

  • Apex primitives (excluding sObject and Blob).
  • sObjects
  • Lists or maps of Apex primitives or sObjects (only maps with String keys are supported).
  • User-defined types that contain member variables of the types listed above.

You didn't post the definition of your MyUserDefinedType class, but I'm guessing that MyUserException is extended from type Exception, which isn't a primitive nor one of the allowed serializable types.

Your best bet for working around this is to remove the exception from MyUserDefinedType and place it outside this class which is attempting to be serialized / deserialized as a parameter.

1
  • 1
    That was my initial though too, but I had also tried moving the Exception inner class out and it didn't resolve the issue. But your reply got me thinking about other disallowed member types and I did add another user-defined member variable to MyUserDefinedType. Once I made it transient, it all compiled fine. Thanks!
    – Mike
    Commented Oct 27, 2022 at 1:21

You must log in to answer this question.

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