1

Possibly a bad question, I am exposing a simple ApexRest Class to accept post's from an external source.

example bellow:

@RestResource(urlMapping='/user_defined_type_example/*')
global with sharing class MyOwnTypeRestResource {

@HttpPost
global static MyUserDefinedClass echoMyType(MyUserDefinedClass ic) {
    return ic;
}

global class MyUserDefinedClass {

    global String string1;
    global String string2;
    global String string3;

}}

Which accepts the input:

<request>
<ic>
    <string1>value for string1</string1>
    <string2>value for string2</string2>
    <string3>value for string3</string3>
</ic></request>

Can I change the root <request> tag to something else?

say <Submission>

1
  • Even if you do that, you will have an overhead of parsing XML via dom parsing Mar 7 '19 at 19:44
1

If you're using the parameterized version of the post body, as you are in your code, it must be formatted using request as the top-level element. This is true for both the XML- and JSON-based parsing options. If you use RestContext.request.requestBody instead, you can choose to create your own format, but you will need to use either Dom.Document or XmlStreamReader to parse the request yourself.

2
  • Sounds good. In the later case; I would take requestbody's blob.tostring() and then load it into the dom.doc right? Mar 7 '19 at 19:24
  • @RyanSherry Yeah
    – sfdcfox
    Mar 7 '19 at 19:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.