Salesforce TutorialHow to developp an Inbound REST Web Service
David Boukhors – Salesforce Expert
David Boukhors - Expert Salesforce 2
Prerequesites
• Sign up for a runscope account:
• https://www.runscope.com
• Create some contact data on your
salesforce org.
David Boukhors - Expert Salesforce 3
Salesforce Administration
• You’ll just need a user with Salesforce
Admin Profile.
David Boukhors - Expert Salesforce 4
Create the APEX Class
Click on New and create an APEX Class with the following code. And Save it.
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
David Boukhors - Expert Salesforce 6
Create an App
Cochez Enable Oauth Settings et donner full access
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)
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
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
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"}
David Boukhors - Expert Salesforce 11
Test the Web Service with Runscope
• Sign on to Runscope and create a
new test with the following
parameter.
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
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
David Boukhors - Expert Salesforce 14
Runscope test Querystring
• Add this parameter, with an email
which refers to an existing contact in
your Salesforce Org
David Boukhors - Expert Salesforce 15
Now run the test!