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
Kam.ax1015Kam.ax1015 

Multiple Post methods in a REST controller

Hello,

 

Is it possible to create multiple POST request which in same controller with some sort of identifier? I could have created custom switch statements but then I need to parse json and it's just a pain as there is no good way to do it in Apex. Thanks, Kam

 

e.g.

 

@RestResource(urlMapping='/ContactAccountController/*')
global class DealAccountRestResource {

@HttpPost
    global static String createAccount(Account account) {
        return account.id;
    }


@HttpPost
    global static String createContact(Contact c) {
        return c.id;
}


@HttpPost
    global static String updateContact(Contact c) {
        return c.id;
}


 

 

 

 

alextalext

This is good feedback. Thanks for sharing with us.

 

--alex

dkadordkador

The answer to this question is not currently.  Your design wouldn't work because there's no way to know which POST method to use.  But the overall request makes sense.  Thanks for the feedback.