How to call heroku java app from salesforce.com? How to call heroku java app from salesforce.com? heroku heroku

How to call heroku java app from salesforce.com?


Yes, this is definitely possible. There is no special communication between Salesforce and Heroku, but the two can talk to each other with regular HTTP APIs. To do this, you would need to:

  1. Expose your PPT generator in a web service running on Heroku. First, take a look at the Getting Started with Java on Heroku article or Getting Started with Play! on Heroku article to get a basic HTTP app up and running on Heroku. Then, drop your PPT generator classes in the app and create an endpoint to access them. For example, you might create an endpoint at /ppt so that if you go to https://example.herokuapp.com/ppt a PPT would be generated and returned in the HTTP response. Of course, you could make the service serve up dynamic PPTs, but keeping it simple for this example.

  2. Call out to your Heroku app from Apex. To do this, take a look at the HTTP RESTful Services Classes in the Apex documentation. For example, you could do something like this in Apex:

    Http h = new Http();HttpRequest req = new HttpRequest();req.setEndpoint('https://example.herokuapp.com/ppt');req.setMethod('GET');HttpResponse res = h.send(req);res.getBody();

If these PPTs are confidential, you'll probably also want to have some kind of authentication scheme between the two system; otherwise, anyone who hits your endpoint could get the PPT. I would at least use Basic Authentication with a shared secret to secure your service, but something fancier could also be used if you wish.

What I've explained above is all through backend APIs, but if you'd like to create a UI for your service in Heroku as well and expose it to Salesforce users, you might want to take a look at the new Force.com Canvas Framework.