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
Miranda L 2Miranda L 2 

How to pass List<String> in post method using Apex

third party need to pass a list of values in the request body of POST method but I get 400: Bad Request error.
Third party JSON using like below
{"entityName":"Invoice","records":[{
"company_id":"YKY7EP1K1",
//below product items will have multiple values which would be in string.
"product_items":["apple","orange"],
"workflow_state":null
}]
}
so how could I develope product_items to assign this array string values to my Invoice object field. Webservice already got developed and its running fine but this new field got created recently and third party want to send in array format so how could I implement it.
Thanks in advance 
EllEll
You could potentially look at converting the "product_items" key from a List<String> into just a list of values and store this on a multi-select picklist.
You'd just need to update whatever custom JSON seraliser you're using to cast "product_items" to the correct List<String> type.

Multi-select just uses a semi-colon as a seperate for each value.
List<String> product_items = new List<String>({'Apple', 'Lemon'});

String value = String.join(product_items, '; ');


 
Miranda L 2Miranda L 2
I have done changes like this way
String value = String.join(product_items, '; ');
assigned this value to String (Invoice Object Text field) 
String value = String.join(product_items, '; ');
now getting following error 
[
    {
        "errorCode": "APEX_ERROR",
        "message": "Exception: Dependent class is invalid and needs recompilation:\n Class InvoiceProcessorWS : Variable is not visible: InvoiceWrapperWS.product_items\n\n"
    }
]

Please suggest
Miranda L 2Miranda L 2
sorry I did not put the "Public" modifier but now the error is same
 
{
    "statusCode": 400,
    "status": "Error",
    "recordReferences": [],
    "errors": [
        {
            "recordId": "Class.System.JSON.deserialize: line 15, column 1\nClass.GlobalWS.processTable: line 33, column 1",
            "errorMessage": "Illegal value for primitive"
        }
    ]
}

please suggest