I'm a little bit confused with rest api endpoints. I developed a rest api using http POST to update some records in salesforce and it has this structure:


where I assume after the word apexrest I'm telling I have a class that will follow that path in my apex class and I'm passing some parameters like id, object and operation:

rest path

and of course I receive the parameters in a good way: parameters

But after doing some research I found I can update a record using an endpoint like this: https://Mydomain.my.salesforce.com/services/**data/v54.0/sobjects/ObjectName/RecordId/**

So the question is what is the difference? or in case I use this path: services/data/v54.0/sobjects/ObjectName/RecordId/ how can I get the request body in apex like in the first example?

Resource: https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_update_fields.htm

1 Answer 1

  • Endpoints that are of the form /services/apexrest/xxxxx are custom APEX-coded endpoints allowing you to do whatever logic you want. You can design your own URL params for GET methods or design your own body (JSON or otherwise) for POST, PUT, PATCH, DELETE methods. A common pattern is for the Apex REST endpoint to take the input and marshal one or more service layer methods in a Separation of Concerns architecture.

  • Endpoints of the form /services/data/vXX.X/... are examples of the OOTB SFDC REST API. There are many other flavors besides updating a single record as you discovered including APIs to:

    • Query for objects (SOQL and SOSL)
    • Do Describes on objects
    • Create objects
    • Delete objects
    • Do DML on batches of objects including related objects (see Composite Resources)
    • and plenty more

The OOTB REST endpoints don't require you to write any APEX at all. The client simply conforms to the specification as documented in the REST API guide and, after authenticating, just sends the HTTP request. Salesforce does the work (the DML or query/describe) and returns an HTTP status code and result body (in JSON).

You must log in to answer this question.

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