Writing a custom service in Apex

Content under development

The ManyWho Drawing Tool is equipped with a rich set of elements that you will find satisfies all your Salesforce app development needs. However, you may find that you need to create a custom service in Apex, because you want to leverage legacy code in your app. You can also create custom code to manage highly complex app logic, or scenarios where your application logic is managed by developers and the tech team. Custom code also comes in handy if you want Salesforce to perform a complex multi-object query.

Here are the broad procedures your friendly neighborhood Apex will follow to write a custom service in Apex:

  1. Creating the Common ManyWho API objects
  2. Telling ManyWho what the service does
  3. Writing the code
  4. Hosting your API
  5. Installing the service in ManyWho

Let’s look at the steps in more detail now.

If you need to take a closer look, click on the images to enlarge them. Have a question? Click the Help button on the bottom right-hand corner of this page to ask.


Telling ManyWho what the service does

Before you can use the custom service in ManyWho, you need to define what the service does. You can do this using the describe API endpoint.

The describe API tells ManyWho ‘what’ this service does, that is the new functions it makes available for the flow builder to use. (Note: The describe API is the description of the service; it is not the actual implementation.)

To illustrate, let’s create a simple Apex class that describes an API call with a single input and single output:

  1. From Setup, click Develop to expand the menu.
  2. Click Apex Classes and click New.
  3. Copy-paste the following code in the class editor.
  4. Click Save.
Note: 

  • The root URL for your service is /something and the describe endpoint is identified with the /metadata extension, as per the RestResource attribute.
  • The developerName constants will be required for the service implementation.
  • The interface is provided as inputs/outputs which can also include List and Object types.

Hosting your API

Force.com sites enable you to create public websites and applications that are integrated with your Salesforce org. Your users can access these sites without having to authenticate themselves. The sites are built on native Visualforce pages, which means data validation on any information collected is done automatically. Users can access your site through your Force.com URL, or a custom domain.

Here’s how you can create a public site to host the API.

(If you already have a public site that you want to use, you can skip Steps 3 to 5, and proceed to Step 6.)

  1. From Setup, click Develop to expand the menu.
  2. Click Sites to open the Sites tab.
  3. Enter a domain name. (You can click the Check Availability button to see if the name is available.)
  4. Check the Sites Terms of Use box to accept the Force.com site terms of use and click Register My Force.com Domain.
  5. You will get an alert box that asks you to confirm the Force.com domain name. Click OK.
  6. Click New.
  7. Enter a label and name for the site in the Site Label and Site Name fields respectively. Example: CustomManyWhoService.
  8. Enter a contact in the Site Contact field.
  9. Click the search icon next to the Active Site Home Page field, and select UnderConstruction.
  10. Check the Require Secure Connections (HTTPS) box.
  11. Click Save.