0

I want to create a single POST method which takes method as a parameter along with the Request body. Using the parameter string method i'm trying to call the related method within my apex controller. But everytime I call this REST API using workbench and passing the method value i'm getting null value for method.

**

@RestResource(urlMapping='/AutomationSFEndPoint/*')
    global without sharing class Automation_SFEndPoint{
        @HttpPost
        global static String handleMethod(string method){
            if(method == 'Create_something'){
                //have some logic
            }
            if(method == 'Create_somethingElse'){
                //have some logic
            }
        }
    }
    //debug log for method is coming null every time

**

2
  • 1
    Welcome to SFSE. I don't see a question articulated here or enough detail to be sure about what's wrong. Could you please take a moment to review How to Ask and help center, then edit your post to add more details so the community can help you? – David Reed Nov 27 '20 at 20:20
  • Please also show us what is your request body, request URL and I dont see a return statement. Please also paste full code for handleMethod but remove the business logic. It might be returning null correctly. – Nagendra Singh Nov 28 '20 at 0:37
0

In order for this to work, you need to format your request in a very specific way. First, the Content-Type header must be set to application/json or application/xml. Then, you must provide the appropriate JSON or XML:

JSON

{ "method": "Hello World" }

XML

<request>
  <method>Hello World</method>
</request>

You can read more in the documentation.

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.