SlideShare a Scribd company logo
SalesforceTutorial
How to developp an Inbound REST Web Service
David Boukhors – Salesforce Expert
Prerequesites
• Sign up for a runscope account:
• https://www.runscope.com
• Create some contact data on your salesforce
org.
David Boukhors - Expert Salesforce 2
Salesforce Administration
• You’ll just need a user with SalesforceAdmin
Profile.
David Boukhors - Expert Salesforce 3
Create the APEX Class
David Boukhors - Expert Salesforce 4
Click on New and create an APEX Class with the following code. And Save it.
@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;
}
}
David Boukhors - Expert Salesforce 5
This code will retrieve a contact based on the Input Email
Create an App
David Boukhors - Expert Salesforce 6
Cochez Enable Oauth Settings et donner full access
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 7
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 8
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
David Boukhors - Expert Salesforce 9
The last parameter is an url which depends on your salesforce org.
Just look at your browser url while using salesforce
• 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/005
2400AG","issued_at":"1437932208386","token_type":"Bear
er","instance_url":"https://eu5.salesforce.com","signature"
:"blablabla","access_token":"MYACCESSTOKEN"}
David Boukhors - Expert Salesforce 10
Test theWeb Service with
Runscope
• Sign on to Runscope and create a new test
with the following parameter.
David Boukhors - Expert Salesforce 11
Runscope test EndPoint
• Add an endpoint:
https://eu5.salesforce.com/services/apexrest/<y
our package name if you have set
one>/getContact
David Boukhors - Expert Salesforce 12
Runscope test Header
David Boukhors - Expert Salesforce 13
• Add the following header
Name = Authorization
Value = Bearer <your runscope access token>
Don’t forget the space between Bearer keyword and your access token
Runscope test Querystring
• Add this parameter, with an email which
refers to an existing contact in your Salesforce
Org
David Boukhors - Expert Salesforce 14
Now run the test!
David Boukhors - Expert Salesforce 15

More Related Content

Similar to Inbound rest web service (20)

PDF
Boxcars and Cabooses: When one more XHR is too much - Peter Chittum - Codemot...
Codemotion
 
PPTX
Secure Development on the Salesforce Platform - Part 3
Mark Adcock
 
POTX
Using the Google SOAP API
Salesforce Developers
 
PDF
SalesForce WebServices part 2
Mindfire Solutions
 
PDF
Building towards a Composite API Framework in Salesforce
Salesforce Developers
 
PPT
Designing custom REST and SOAP interfaces on Force.com
Steven Herod
 
PDF
Secure Salesforce: External App Integrations
Salesforce Developers
 
PPTX
Salesforce Integration using REST SOAP and HTTP callouts
RAMNARAYAN R
 
PPTX
Using Apex for REST Integration
Salesforce Developers
 
PPTX
Salesforce Integration with MuleSoft | MuleSoft Mysore Meetup #12
MysoreMuleSoftMeetup
 
PDF
Designing Custom REST and SOAP Interfaces on Force.com
Salesforce Developers
 
PPTX
Apex REST
Boris Bachovski
 
PPTX
CRM Science - Dreamforce '14: Using the Google SOAP API
CRMScienceKirk
 
PDF
Getting Started With Apex REST Services
Salesforce Developers
 
DOCX
Salesforce Integration
Er. Prashant Veer Singh
 
PDF
[MBF2] Webinar plate-forme Salesforce #1
BeMyApp
 
PDF
[MBF2] Webinar plate-forme Salesforce #1
BeMyApp
 
PPTX
SFDC REST API
Bohdan Dovhań
 
PPTX
Episode 11 building & exposing rest api in salesforce v1.0
Jitendra Zaa
 
PPTX
Integrating with salesforce
Mark Adcock
 
Boxcars and Cabooses: When one more XHR is too much - Peter Chittum - Codemot...
Codemotion
 
Secure Development on the Salesforce Platform - Part 3
Mark Adcock
 
Using the Google SOAP API
Salesforce Developers
 
SalesForce WebServices part 2
Mindfire Solutions
 
Building towards a Composite API Framework in Salesforce
Salesforce Developers
 
Designing custom REST and SOAP interfaces on Force.com
Steven Herod
 
Secure Salesforce: External App Integrations
Salesforce Developers
 
Salesforce Integration using REST SOAP and HTTP callouts
RAMNARAYAN R
 
Using Apex for REST Integration
Salesforce Developers
 
Salesforce Integration with MuleSoft | MuleSoft Mysore Meetup #12
MysoreMuleSoftMeetup
 
Designing Custom REST and SOAP Interfaces on Force.com
Salesforce Developers
 
Apex REST
Boris Bachovski
 
CRM Science - Dreamforce '14: Using the Google SOAP API
CRMScienceKirk
 
Getting Started With Apex REST Services
Salesforce Developers
 
Salesforce Integration
Er. Prashant Veer Singh
 
[MBF2] Webinar plate-forme Salesforce #1
BeMyApp
 
[MBF2] Webinar plate-forme Salesforce #1
BeMyApp
 
SFDC REST API
Bohdan Dovhań
 
Episode 11 building & exposing rest api in salesforce v1.0
Jitendra Zaa
 
Integrating with salesforce
Mark Adcock
 

Inbound rest web service

  • 1. SalesforceTutorial How to developp an Inbound REST Web Service David Boukhors – Salesforce Expert
  • 2. Prerequesites • Sign up for a runscope account: • https://www.runscope.com • Create some contact data on your salesforce org. David Boukhors - Expert Salesforce 2
  • 3. Salesforce Administration • You’ll just need a user with SalesforceAdmin Profile. David Boukhors - Expert Salesforce 3
  • 4. Create the APEX Class David Boukhors - Expert Salesforce 4 Click on New and create an APEX Class with the following code. And Save it.
  • 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; } } David Boukhors - Expert Salesforce 5 This code will retrieve a contact based on the Input Email
  • 6. Create an App David Boukhors - Expert Salesforce 6 Cochez Enable Oauth Settings et donner full access
  • 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 7
  • 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 8
  • 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 David Boukhors - Expert Salesforce 9 The last parameter is an url which depends on your salesforce org. Just look at your browser url while using 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/005 2400AG","issued_at":"1437932208386","token_type":"Bear er","instance_url":"https://eu5.salesforce.com","signature" :"blablabla","access_token":"MYACCESSTOKEN"} David Boukhors - Expert Salesforce 10
  • 11. Test theWeb Service with Runscope • Sign on to Runscope and create a new test with the following parameter. David Boukhors - Expert Salesforce 11
  • 12. Runscope test EndPoint • Add an endpoint: https://eu5.salesforce.com/services/apexrest/<y our package name if you have set one>/getContact David Boukhors - Expert Salesforce 12
  • 13. Runscope test Header David Boukhors - Expert Salesforce 13 • Add the following header Name = Authorization Value = Bearer <your runscope access token> Don’t forget the space between Bearer keyword and your access token
  • 14. Runscope test Querystring • Add this parameter, with an email which refers to an existing contact in your Salesforce Org David Boukhors - Expert Salesforce 14
  • 15. Now run the test! David Boukhors - Expert Salesforce 15