3

I plan to develop an integration pipeline between two salesforce dev orgs for the following use case.

Use Case :

Send a custom object record (having two string fields only) from Salesforce Developer Box (S1) to Salesforce Developer Box (S2).

Features to be developed

  1. Create a REST Webservice in S2 which will consume the payload sent to it from S1 and create a record in S2. (PUT request)
  2. Create a REST Webservice in S2 which will return true or false depending upon the input query parameter in the payload. (GET request)

Questions

a) How the authentication will be handled for the integration request from S1 to S2 ?.

b) How do we actually invoke the REST Webservices in S2 from S1 ?.

Would appreciate any pointers or links or guidance for my above questions :)

PS:

In our company we use TIBCO for all our integration needs as such we never used Salesforce API for integration needs. I am aware that we can achieve Salesforce to Salesforce Integration via OOTB functionality but I would like to experiment with REST/JSON setup instead of relying on the OOTB functionality. :)

3

a) How the authentication will be handled for the integration request from S1 to S2 ?.

Some people implement a username and password, calling a SOAP login (this is trivially implemented using WSDL2Apex using a modified enterprise.wsdl), while others may prefer to implement an OAuth2 web server flow, user-client flow, or even username-password flow. It's also possible (but very insecure) to simply use an unauthenticated REST setup via Sites. I would personally use the Web Server flow, which is the most secure of all the options when implemented appropriately. You'll need some Visualforce pages for this to work, however.

b) How do we actually invoke the REST Webservices in S2 from S1 ?.

Once authenticated, it's simply a matter of calling the service. It would look roughly like this:

HttpRequest req = new HttpRequest();
req.setMethod(method); // GET, PUT, POST, etc
req.setEndpoint(serverUrl+restCommand); // eg https://na1.salesforce.com/services/data/v32.0/sobjects/Account
Http binding = new Http();
HttpResponse res = binding.send(req); // note: CalloutException is possible
// handle the response here

You'll need the REST API Developer's Guide as your primary resource. See Getting Started / Introduction / Understanding Authentication / Using Web-Server ... for logging in, and the REST API reference there for which URLs to use.

You'll also find the Force.com Apex Code Developer's Guide handy for understanding Http, HttpRequest, HttpResponse, and JSON.

  • Thanks..instead of invoking webservice (lets us say PUT request) from VF...Can't I put that invocation within a trigger ? – Varun Mar 30 '15 at 15:49
  • You can call it asynchronously using Batchable or Queueable, but not directly from the trigger (you'll get an exception). – sfdcfox Mar 30 '15 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.