inbound rest web service

15
Salesforce Tutorial How to developp an Inbound REST Web Service David Boukhors – Salesforce Expert

Upload: david-boukhors

Post on 18-Aug-2015

35 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Inbound rest web service

Salesforce TutorialHow to developp an Inbound REST Web Service

David Boukhors – Salesforce Expert

Page 2: Inbound rest web service

David Boukhors - Expert Salesforce 2

Prerequesites

• Sign up for a runscope account:

• https://www.runscope.com

• Create some contact data on your

salesforce org.

Page 3: Inbound rest web service

David Boukhors - Expert Salesforce 3

Salesforce Administration

• You’ll just need a user with Salesforce

Admin Profile.

Page 4: Inbound rest web service

David Boukhors - Expert Salesforce 4

Create the APEX Class

Click on New and create an APEX Class with the following code. And Save it.

Page 5: Inbound rest web service

David Boukhors - Expert Salesforce 5

@RestResource(urlMapping='/getContact/*’)

global with sharing class RestWSDemo {

@HttpGet

global static List<Contact> getContact() {

String Email = RestContext.request.params.get('Email');

List<Contact> contactResult = [ Select ID, Name, Description, Birthdate from Contact

where Email = :Email];

return contactResult;

}

}

This code will retrieve a contact based on the Input Email

Page 6: Inbound rest web service

David Boukhors - Expert Salesforce 6

Create an App

Cochez Enable Oauth Settings et donner full access

Page 7: Inbound rest web service

David Boukhors - Expert Salesforce 7

Consumer Key and Secret• Now click on your created app and

you’ll find two usefull information a

consumer key and a consumer

secret, under API (Enable Oauth

Settings section)

Page 8: Inbound rest web service

David Boukhors - Expert Salesforce 8

How to get your security token

• Go to Your Name >

Settings and select

Personal > Reset my

security token

• You will receive your

security token by mail

Page 9: Inbound rest web service

David Boukhors - Expert Salesforce 9

Generate an access token for Runscope

• Open a terminal (on Unix environment) and run this command:

curl --form client_id=<your consumer key> \

--form client_secret=<your consumer secret> \

--form grant_type=password \

--form username=<your salesforce username (email)> \

--form password=<password concatenated with security

token> \

https://eu5.salesforce.com/services/oauth2/token

The last parameter is an url which depends on your salesforce org. Just look at your browser url while using salesforce

Page 10: Inbound rest web service

David Boukhors - Expert Salesforce 10

• You’ll get this kind of answer, which is a token for

runscope, valid only for one hour:

• > https://eu5.salesforce.com/services/oauth2/token

• {"id":"https://login.salesforce.com/id/

000000YMstEAG/

0052400AG","issued_at":"1437932208386","token_typ

e":"Bearer","instance_url":"https://

eu5.salesforce.com","signature":"blablabla","access_to

ken":"MYACCESSTOKEN"}

Page 11: Inbound rest web service

David Boukhors - Expert Salesforce 11

Test the Web Service with Runscope

• Sign on to Runscope and create a

new test with the following

parameter.

Page 12: Inbound rest web service

David Boukhors - Expert Salesforce 12

Runscope test EndPoint

• Add an endpoint:

https://eu5.salesforce.com/services/ap

exrest

/<your package name if you have set

one>/getContact

Page 13: Inbound rest web service

David Boukhors - Expert Salesforce 13

Runscope test Header

• Add the following header

Name = Authorization

Value = Bearer <your runscope access

token>

Don’t forget the space between Bearer keyword and your access token

Page 14: Inbound rest web service

David Boukhors - Expert Salesforce 14

Runscope test Querystring

• Add this parameter, with an email

which refers to an existing contact in

your Salesforce Org

Page 15: Inbound rest web service

David Boukhors - Expert Salesforce 15

Now run the test!