2

I'm working with integrations rn, and I'm stuck...

I need to create a public site to receive calls fired by a third-party system. I'm using this tutorial: http://www.wadewegner.com/2013/03/creating-anonymous-rest-apis-with-salesforce-com/ .

My classes are described below:

@RestResource(urlMapping='/Lead/*')
Global class ReceivesLead {
    
    global static String NewLead(
        String email,
        String name,
        String mobile_phone,
        String Status,
        String LeadSource,
        String Vehicle__c,
        String campaign)
    {
        Lead ld             = new Lead();
        ld.LastName         = name;
        ld.Email            = email;
        ld.MobilePhone      = mobile_phone;
        ld.Status           = 'xxxx';
        ld.LeadSource       = 'xxxx';
        ld.Vehicle__c       = 'xxxx';
        ld.IdCampaign__c    = campaign;
        insert ld;
        return 'Done';

And I send the following JSON to test it:

 "name":"xxxxxn",
 "mobile_phone":"6848446546",
 "Status":"example",
 "LeadSource":"example",
 "Vehicle__c":"example",
 "campaign":"example",
}

And I'm receiving the following error from postman:

    {
        "errorCode": "METHOD_NOT_ALLOWED",
        "message": "HTTP Method 'POST' not allowed. Allowed are "
    }
]

Thanks in advance!!!

1 Answer 1

4

You need to annotate your POST handler method with the @httpPost decorator. That way Salesforce knows to run that method when the REST Request method from outside is set to "POST".

It should look like this:

@httpPost global static String NewLead(...){...}

Here's the Documentation

1
  • Thanks John, it worked! I was so focused searching that I couldn't find it was missing!
    – RedMan
    Commented Jul 7, 2020 at 0:21

You must log in to answer this question.

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