Trialforce | Using custom Salesforce API to work with Restforce gem on Ruby on Rails

by - 12:13 AM

In the last post, I talked about architecture and product details of Trialforce, in here I'll be discussing

Image by William Yeh
the viable workaround for set of audiences who develop application on rails, host on heroku (or similar) platform and consume SignupRequest object to spin application trials. Primarily there two popular gem in the world of Ruby on Rails ( gem and RestForce gem). I'll be talking about, the advantages of using RestForce over gem, and how we use it to talk to custom salesforce api that can spin trials. Below are some easy code-snippets that you find on the their restforce gem docs to play with to salesforce resources.

To get started with RESTForce, just include gem in your rails application and run bundle install

You can perform few of the coolest methods you can use with RESTForce gems like shown in snippet here, but I recommend reading Bruno Fangundez post here

What special does Restforce have, over gem ?

Basically, RestForce gem support proxy_url while gem do not and at the same time, you can write custom endpoint or api in Apex (salesforce) and consume them through Restforce.

Does RESTForce Gem support Trialforce object (SignupRequest) ?

No, RestForce do not recognize this new standard object, but workaround is that RestForce support custom endpoints, so if we can expose SignupRequest through an custom API, we can consume this object from here.I have written a blog post  here with some good design practices, explaining how to built custom endpoint and design your own api in Apex. I have built a sample API that post (insert) a record in SignupRequest object and another method to check the status of spinning org through these endpoints to resolve this issue.

Since I render JSON on client to read response from API, I stress on writing a response handler class that return custom classtype object as response.

Create an API class with bunch of attributes that we want to our client to consume

Now I wrote a simple API class in Apex exposing custom method through endpoints (@Trailforce) which simply insert a new record in SignupRequst, which in turn spin the org. In here, since we have exposed custom class, we can easily consume it through RestForce Gem.

Below are POST method of API to spin Trials

Get method retrieve the current status of trial account

Use RESTForce gem to create client connection and get the status of the trial by calling @HttpGet Method

Read more about RestForce on the official repo here

You May Also Like