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
Tim BarsottiTim Barsotti 

Is it possible to use attributes with Rest Services?

I have a rest resource configured similar to below. I would like to be able to read the attributes that are passed in with each element, but have not found a way to do this. It appears that SF automatically maps the elements of the request into the user defined object and does not appear to allow me to access any of the attributes. Is there a method to access the original payload?

 

Ideally, I'd like to be able to access project and method from the request as logic is dependent on these fields. 

 

<request project="MyProject" method="NewTest">

     <Field1 attribute1="123">test</Field1>

</request>

 

@RestResource(urlMapping='/test/*')
    global class test{
          @HttpPost
          global static List<String> n(UserDefinedObject UDO){
                RestRequest req = RestContext.request;
                system.debug(req); //does not contain payload
                system.debug(UDO); //Already parsed out object - all attributes are gone

 

Thanks!