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
Bill McBill Mc 

unknown exception when inserting Case in REST APEX

 am attempting to insert a Case object in response to a REST post request (its a web hook for a customer support chat service).

I can insert a custom object fine.

But when I try to insert a Case I get : UNKNOWN_EXCEPTION, invalid parameter value: [].

I have tried the exact same code outside of the REST Apex class and it works fine. 

All help appreciated.

Kind regards,  Bill

@RestResource(urlMapping='/test')
global class TestWebHook {
    @HttpGet
    global static String doGet() {
    }
    @HttpPost
    global static String doPost() {
        
        Case mycase = new Case();
        insert mycase;
    }
     
Raj VakatiRaj Vakati
Step 1 : Update your code as shown below 
@RestResource(urlMapping='/test')
global class TestWebHook {
    @HttpGet
    global static String doGet() {
        return '';
    }
    @HttpPost
    global static String doPost(String caseSub , String priority ,String status , String org) {
        Case mycase = new Case();
        mycase.Subject =caseSub ; 
        
        mycase.Status =status ; 
        mycase.Origin =org ; 
        mycase.Priority =priority ;
        insert mycase;
        return mycase.Id ; 
    }
}

Step 2: Go to workbench  then  utilities --> Apex Rest exporter as shown below 
https://workbench.developerforce.com/restExplorer.php
and use this body 
{
  "caseSub" : "Case is Created",
  "priority" : "Low",
"status":"New",
"org":"web"
}

Click on Execute it will create a case and you can able to see the response 
User-added image