Sitemap

Scalable Apex Service Repo

3 min read3 days ago

I’m Joe Gillick, I work at Ripple as a Salesforce Engineer and Manager.

The scope is to create an apex rest service converter (converting salesforce tables to JSON) that is somewhat recognizable to Spring Boot or Java engineers. This was something I did to be able to break down barriers between traditional engineering teams and allow for better collaboration.

Use Case Example:

As an internal Engineer, I need to grab multiple objects into a singular JSON across multiple endpoints and use cases.

Here is the repo: for forking.

This assumes an intermediate to advanced understanding of Apex.

Here are a few prerequisites you’ll need to test:
1. A knowledge of Connected Apps to create a bearer

2. A knowledge of curl and/or Postman (or any integration UI)

Structure:

  • RestService (Interface)
  • RestConfig (Class)
  • RestInfoImpl (Class)
  • RestServiceTest (Test Class)
  • RestUtil (Class)
  • RestStringUtil (Class)

The first issue to solve was the class-level rest resource annotations. Without being able to allow for endpoint mapping to methods, we need to be able to create a scalable solution that doesn’t get out of hand with classes and duplicative code.

I solved this with:

@RestResource(urlMapping=’/joe-gillick/*’)

The star endpoint mapping allows us to control it at the code level like so:

This is being validated in the controller class prior to hitting the config:

The next challenge was to use some basic polymorphism to allow for the controller to stay lean. In the first picture above you can see the RestService being initialized.

This is our interface for our endpoint implementations:

We then implement the endpoint like so:

This directly maps to /info as seen in the initial picture, and the config class handles casting for you:

Final GET Response:

No responses yet