• cipto cipto
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi there,
I'm exposing an apex class as REST.
@RestResource(urlMapping='/Opportunity/*')
global with sharing class OpportunityResource {
   @HttpGet
   global static Opportunity doGet() {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        String opportunityId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
        Opportunity result = [select
        Id,
        Account.Id,
        Account.Name,
        Account.Phone,
        Account.Fax,
        Account.Website,
        Account.Type,
        Account.NumberOfEmployees,
        Account.BillingCountry,
        Account.BillingStreet,
        Account.BillingCity,
        Account.BillingState,
        Account.BillingPostalCode,
        Account.Service_Rep_Email__c,
        Account.Industry,
        Account.Special_Contract_Terms__c,
        Account.Billing_Terms__c,
        Account.PEPY__c,
        Number_of_Employees__c,
        Number_of_Sessions__c,
        Product__c,
        Brand__c,
        Benefit_Tier__c,
        Effective_Date__c,
        Number_of_Training_Visits__c,
        Number_of_Trauma_Responses__c,
        Premium_Per_Employee__c
        from Opportunity
        where Id = :opportunityId
        limit 1];
        return result;
    }
    @HttpPost
    global static String doPost(String name,String description) {
        Opportunity opportunity = new Opportunity();
        opportunity.Name = Name;
        opportunity.Description = Description;
        insert opportunity;
        return opportunity.Id;
    }
}

The HTTP Get query works just fine 
curl -X GET \
  https://xxx.lightning.force.com/services/apexrest/Opportunity/0065C0000050OLGQA2 \
  -H 'authorization: Bearer xxx' \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'postman-token: 7ba978b9-f2e8-fd39-b52f-039e5c3d194b' \


But when doing the POST, I don't know why always return
METHOD NOT ALLOWED "GET" Please use POST
 
curl -X POST \
	  https://xxx.force.com/services/apexrest/Opportunity/ \
	  -H 'authorization: Bearer xxx' \
	  -H 'cache-control: no-cache' \
	  -H 'content-type: application/json' \
	  -H 'postman-token: 885fbd88-3171-d7cf-2dfa-7a782a3e5df8' \
	  -d '{
	 "name":"PT ABAL ABAL",
	 "description":"PT Abal"
	}
	'

Any body have an idea why it's happening?
am I missing a configuration or something?
this is pointing to a sandbox lightning.
 
Hey all, I'm making a callback Apex class that's supposed to act differently depending on whether it gets a GET call or a POST call to a specific endpoint. The callback class has two exposed methods, doGet() and doPost() annotated with @HttpGet and @HttpPost respectively like this:

@RestResource(urlMapping='/inMobileCallback') global with sharing class InMobileCallback {
@HttpGet
global static void doGet() {
// Logic
}
@HttpPost
global static void doPost(){
// logic
}

But when I try to make a POST request to the designated REST endpoint using Postman (https://www.getpostman.com/), I get a 500 response (with or without a body):
User-added image


and from looking in my custom Apex Errors Report I can see that this is due to it trying to run the doGet() (which, naturally, fails due to there being none of the expected GET parameters):
User-added image

So, basically, what is happening is that despite explicitly sending a POST request, Salesforce runs the doGet() instead of doPost(). Since doGet() is the first method in the class, my guess is that either it's somehow just ignoring the annotations altogether or it misinterprets the POST request from Postman as a GET request... regardless, I'm thoroughly confused by this. Have anyone seen anything like this?