function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
GYAN ANDRUSGYAN ANDRUS 

Hi Everyone,Please help me,I want to create a post method,I need to send a json format

if any records created in Custom object,I hve written code,I have added the URL in Remote site settings,But in POSTMAN is not working
MY POSTMAN URL:https://aci--uat.cs23.my.salesforce.com/services/apexrest/WSItemMasterProductFacilities
REMOTE SITE SETTING URL:https://aci--uat.cs23.my.salesforce.com

@RestResource(urlMapping='/WSItemMasterProductFacilities')
global class  WSItemMasterProductFacilities {
    
     @HttpGet
    global static List<PBSI__PBSI_Item__c> getWidgets() {
        List<PBSI__PBSI_Item__c> widgets = [SELECT Name from PBSI__PBSI_Item__c];
        return widgets;
    }
    @HttpPost
    global static List<PBSI__PBSI_Item__c> ItemMasterProductFacilities()
    {
       List<PBSI__PBSI_Item__c> itemMaster;
       
        try
        {
         RestRequest req = RestContext.request;
         String NameValue = req.params.get('name');   
         itemMaster = [Select id,Name from PBSI__PBSI_Item__c];   
         return itemMaster;  
            }
        catch(Exception e)
        {
        System.debug('Line Number is = '+e.getLineNumber()+' Message is = ' +e.getMessage());
         }
        return itemMaster;  
        
    }
}
pconpcon
Can you please provide a cURL or an example of how you are making the POST call to this endpoint?  You do not have a variable as a parameter to your HttpPost method, so there is nothing to actually post.  using the req.params.get('name') means that you have the ?name=foo in your URL.

NOTE: When adding code please use the "Add a code sample" button (icon <>) to increase readability and make it easier to reference.