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!!!

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

| improve this answer | |
  • Thanks John, it worked! I was so focused searching that I couldn't find it was missing! – Growred Jul 7 at 0:21

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.