5

I have a requirement where we will receive a parent product id and List of childProductInfo from other system.

Our task in SFDC will be to find the existing parent product (1st input parameter : string parentProdId) and search for existing child product (2nd input parameter : List<childProductInfo>).

If we will find all incoming child parameters are there in SFDC then its ok , if there are indeed some new feed is coming, then insert new products with the parameters given as input.

I have implemented this requirement as SOAP web service.

But, I want to implement this as REST API.

I know we have to write a global static post method (@HttpPost), but can we pass a List as a parameter ?

1
  • 1
    Did you try that and receive any error?
    – Patlatus
    Feb 14, 2016 at 9:07

1 Answer 1

6

Providing childProductInfo can be serialized (which is can if it is a simple Apex class) an @HttpPost can handle a List:

@RestResource(urlMapping='/xxx/*') 
global class Temp {

    global class ChildProductInfo {
        public String info;
        public Integer moreInfo;
        // ...
    }

    @HttpPost
    global static void doPost(Id parentProdId, List<ChildProductInfo> childProdInfos) {
        // ...
    }
}

In my experience with @RestResource any signature problems are reported at compile time.

The JSON to be posted to the above would look like this:

{
    "parentProdId": "...",
    "childProdInfos": [{"info": "abc", "moreInfo": 123}, {"info": "xyz", "moreInfo": 789}]
}
1
  • Thank you!. With the help of above data and with the workbench REST tool. I could able to understand the flow. Feb 14, 2016 at 19:33

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.