1

In salesforce apex, I have one custom API, It's working fine on the workbench but not work on POSTMAN, I have an access token, this works fine with GET method, but why not work with POST in POSTMAN?

APEX custom POST api is

@RestResource(urlMapping='/contactapi/*')
global with sharing class PostContactResouceWithParameter {
    @HttpPost
    global static String createNewContact(String firstName, String lastName, String birthDate, String leadSource) {
        Contact contact = new Contact();
        contact.FirstName = firstName;
        contact.LastName = lastName;
        contact.Birthdate = Date.parse(birthDate);
        contact.LeadSource = leadSource;

        //insert contact;

        return 'success';
    }
}

enter image description here

enter image description here

After POST always get 405 status.

1 Answer 1

2

I can see in image your ContactAPI c is in Caps. Also change your url to VF Domain (Classic). I can see you have lightning domain in your rest URL. If you are unsure how to get that then please use this as anonymous apex:

System.debug(Url.getOrgDomainUrl().toExternalForm() + '/services/apexrest/contactapi');

Use this api as you REST URL.

13
  • Follow your instruction, after return the string from API, get status 405 with the message. [ { "errorCode": "METHOD_NOT_ALLOWED", "message": "HTTP Method 'GET' not allowed. Allowed are POST" } ]
    – shamim
    Commented Nov 27, 2020 at 9:49
  • I updated my answer, but I never told to fire a GET request, why is this message coming up, I tried with same code and it works fine, the only diff I see is your image has ContactAPI as caps whereas your rest controller has it in small. Commented Nov 27, 2020 at 9:56
  • I told you that I follow your instruction, change the URL, and request on POST, but get 405 as a response.
    – shamim
    Commented Nov 27, 2020 at 10:28
  • Can you paste you request again? Commented Nov 27, 2020 at 10:33
  • I updated my answer, please check.
    – shamim
    Commented Nov 27, 2020 at 10:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .