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
Satya sai sudhirSatya sai sudhir 

How do i create a REST end point in salesforce and make it public and it should accept an Integer as argument/parameter and triple it and send the response.? Any help will e appreciated i'm still a newbie!

How to create a REST end point in salesforce and make it public and it should accept an Integer as argument/parameter and triple it and send the response.
Bhaswanthnaga vivek vutukuriBhaswanthnaga vivek vutukuri
@RestResource(urlMapping='/Merchandise/*')
global with sharing class MerchandiseManager {
  
    @HttpGet
    global static Merchandise__c getMerchandiseById() {
        RestRequest req = RestContext.request;        
        String merchId = req.requestURI.substring(
                                  req.requestURI.lastIndexOf('/')+1);
        Merchandise__c result = 
                       [SELECT Name,Description__c,Price__c,Total_Inventory__c
                        FROM Merchandise__c 
                        WHERE Id = :merchId];
        return result;
    }
  
    @HttpPost
    global static String createMerchandise(String name,
        String description, Decimal price, Double inventory) {
        Merchandise__c m = new Merchandise__c(
            Name=name,
            Description__c=description,
            Price__c=price,
            Total_Inventory__c=inventory);
        insert m;
        return m.Id;
    }
}


https://developer.salesforce.com/docs/atlas.en-us.apex_workbook.meta/apex_workbook/apex_rest_1.htm

Please find the above link

Marek Kosar_Marek Kosar_
Hello,
to make it public, you have to place it into sites, here is guide how to do it :
https://developer.salesforce.com/blogs/developer-relations/2012/02/quick-tip-public-restful-web-services-on-force-com-sites.html

And rest method like:
@RestResource(urlMapping='/trippleInteger')
  global class MyService {
    @HttpGet
    global static Integer trippleIt() {
        String someNumber = RestContext.request.params.get('yourInteger');
        return someNumber *3;
    }
}

And just call it:
yourSiteUrl../services/apexrest/trippleInteger?yourInteger=123