Your SlideShare is downloading. ×
SalesForce WebServices part 2
SalesForce WebServices part 2
SalesForce WebServices part 2
SalesForce WebServices part 2
SalesForce WebServices part 2
SalesForce WebServices part 2
SalesForce WebServices part 2
SalesForce WebServices part 2
SalesForce WebServices part 2
SalesForce WebServices part 2
SalesForce WebServices part 2
SalesForce WebServices part 2
SalesForce WebServices part 2
SalesForce WebServices part 2
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

SalesForce WebServices part 2

2,357

Published on

This presentation is all about - SalesForce REST Webservice.

This presentation is all about - SalesForce REST Webservice.

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,357
On Slideshare
0
From Embeds
0
Number of Embeds
9
Actions
Shares
0
Downloads
277
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Webservices In Salesforce (Part 2) Rest Services Presenter: Suryakanta Mekap, Mindfire Solutions Date: 24/01/2014
  • 2. Presenter: Surya Kanta Mekap, Email: suryam@mindfiresolutions.com SkypeId: mfsi_suryam https://www.facebook.com/surya.mekap Date: Jan 24th 2014 Filemaker Certified Developer Salesforce Certified Developer Presenter:Suryakanta Mekap, Mindfire Solutions
  • 3. Overview 1. Recap 2. REST Webservice 3. Public REST Webservice 3. REST Callout 4. Test classes for webservices 5. Summary Presenter: Suryakanta Mekap, Mindfire Solutions
  • 4. Steps for Creation Step One: Obtain a Salesforce Developer Edition Organization Step Two: Create class that will work as REST webservice Step Three: Set Up Authorization Step Four: Send HTTP Requests Presenter: Suryakanta Mekap, Mindfire Solutions
  • 5. REST Webservice 1. First, create and define an Apex class as global with keyword "@RestResource" to signify the class responsible for handling HTTP requests and act as REST based web service. @RestResource(urlMapping='/TestREST/') global with sharing class HelloWorld { @HttpGet global static string sayHelloWorld() {{ return 'Hello'; } } The global access modifier declares that the class is visible to all Apex scripts everywhere. This means the class can be used by any Apex code, not just the Apex in the same application. Presenter: Suryakanta Mekap, Mindfire Solutions
  • 6. REST Webservice(Continued...) 2. The urlMapping property allows us to set the endpoint(where the service will be available) . Example: https://ap1.salesforce.com/services/apexrest/TestREST/ 3. @HttpGet, @HttpPost, @HttpDelete, @HttpPut, @HttpPatch keyword must be included before the methods to respond on a GET, POST , DELETE, PUT and PATCH calls respectively. 4. The methods responsible for handling HTTP requests have global access specifier and static keyword with them. 5. We can use RestRequest object in a method to pass parameters to the service. 6. The limitation is that you can declare only one method for each @HttpGet, @HttpPost, @HttpDelete, @HttpPut, @HttpPatch keyword to respond for each http type request. Presenter: Suryakanta Mekap, Mindfire Solutions
  • 7. Oauth 2.0 Salesforce uses authentication to allow users to securely access data Supported OAuth flows include:  Web server flow, where the server can securely protect the consumer secret.  User-agent flow, used by applications that cannot securely store the consumer secret.  Username-password flow, where the application has direct access to user credentials. After successfully authenticating the user, you’ll receive an access token which can be used to make authenticated REST API calls. A remote access/connected app application is an application external to Salesforce that uses the OAuth protocol to verify both the Salesforce user and the external application. Presenter: Suryakanta Mekap, Mindfire Solutions
  • 8. Oauth 2.0 (Continued...) OAuth endpoints are the URLs you use to make OAuth authentication requests to Salesforce. You need to use the correct Salesforce OAuth endpoint when issuing authentication requests in your application. The primary OAuth endpoints are: For authorization: https://login.salesforce.com/services/oauth2/authorize For token requests: https://login.salesforce.com/services/oauth2/token For revoking OAuth tokens: https://login.salesforce.com/services/oauth2/revoke All endpoints require secure HTTP (HTTPS). Presenter: Suryakanta Mekap, Mindfire Solutions
  • 9. Public REST Webservice 1) Create a REST webservice. 2) Go to Site > Setup > App Setup > Develop > Sites > Select your Site > Give access of webservice class to site profile. Lets say this is the location: https://ap1.salesforce.com/services/apexrest/TestREST/HelloWorld And our site URL is https://mindfire-surya-developer-edition.ap1.force.com/ So our final location will be: https://mindfire-surya-developeredition.ap1.force.com/services/apexrest/TestREST/HelloWorld Now you can use this location and there will be no need of getting any access tokens or session Ids. Presenter: Suryakanta Mekap, Mindfire Solutions
  • 10. REST Callout Apex Callouts enable Apex to invoke external web services so that you connect to third party services. Before any Apex callout can call an external site, that site must be registered in the Remote Site Settings page, or the callout fails.  Salesforce prevents calls to unauthorized network addresses. Skipping this will result in "System.CalloutException: IO Exception: Unauthorized endpoint, please check Setup->Security->Remote site settings. endpoint ="... Presenter: Suryakanta Mekap, Mindfire Solutions
  • 11. REST Callout(Continued...) 1. Apex provides several built-in classes(HTTP, HTTPRequest, HTTPResponse) to work with HTTP services and create HTTP requests like GET, POST, PUT, and DELETE. (It also enables the ability to integrate to SOAP-based web services as an alternate option to leveraging WSDL2Apex. By using the HTTP classes, instead of WSDL2Apex, the developer has more responsibility to handling the construction of the SOAP message both for the request and the response. ) 2. Below is a sample example of Restful callout you can make to know the location of the IP address sent: Suppose we want to send HTTP GET requests to: http://www.freegeoip.net/{format}/{ip_or_hostname} and the supported response format is csv, xml, json. Presenter: Suryakanta Mekap, Mindfire Solutions
  • 12. References http://wiki.developerforce.com/page/Apex_Web_Services_and_Callouts http://forceguru.blogspot.in/2012/09/creating-public-web-service-in.html http://blog.deadlypenguin.com/blog/2012/02/03/salesforce-and-soapui/ http://kperisetla.blogspot.in/2012/05/restful-services-on-forcecom-through.html http://www.fishofprey.com/2011/03/consuming-aspnet-web-service-from.html http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_callouts_wsdl2apex.htm http://www.salesforce.com/us/developer/docs/apexcode/index.htm http://stackoverflow.com/questions/209905/representational-state-transfer-rest-and-simple-object-a http://www.salesforce.com/us/developer/docs/api_rest/index_Left.html http://blog.deadlypenguin.com/blog/2012/04/13/salesforce-and-soapui-using-the-default-query-met http://medbiq.org/std_specs/techguidelines/knowingwhentorest.pdf http://www.developingthefuture.net/web-services-overview/ http://www.tgerm.com/2010/12/invoking-apex-wsdl-web-services-from.html http://blogs.developerforce.com/tech-pubs/2011/10/salesforce-apis-what-they-are-when-to-use-them Presenter: Suryakanta Mekap, Mindfire Solutions
  • 13. Question and Answer Presenter: Suryakanta Mekap, Mindfire Solutions
  • 14. Thank you Presenter: Suryakanta Mekap, Mindfire Solutions

×