SlideShare una empresa de Scribd logo
1 de 4
Invoking Callouts Using Apex

Invoking Callouts Using Apex
* An Apex callout enables you to tightly integrate your Apex with an external service by making
a call to an external Web service or sending a HTTP request from an Apex script and then
receiving the response.

Tightly Couple Architecture

* Apex provides integration with Web services that utilize SOAP and WSDL, or HTTP services
(RESTful services).
Note:
Note: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.
* Callouts enable Apex to invoke external web or HTTP services.
*Apex Web services allow an external application to invoke Apex methods through Web
services.
Adding Remote Site Settings
To add a remote site setting:
1. Click Your Name ➤ Setup ➤ Security Controls ➤ Remote Site Settings.
2. Click New Remote Site.
3. Enter a descriptive term for the Remote Site Name.
4. Enter the URL for the remote site.
5. Optionally, enter a description of the site.
6. Click Save.
Types of WSDL's
1. Enterprise WSDL
* It is a big WSDL which contains information about schema of organization.
* Strictly Typed: For Integer if we give 3.19 like that then it will not accept and throw error.
* When schema is modified then we have to recreate new enterprise WSDL.
2. Partner WSDL
* Loosly Typed: For Integer if we give 3.19 like that then it will accept and not throw error.
* When schema is modified then it will automatically updated.
SOAP Services: Defining a Class from a WSDL Document
* Classes can be automatically generated from a WSDL document that is stored on a local hard
drive or network.
* Creating a class by consuming a WSDL document allows developers to make callouts to the
external Web service in their Apex scripts.
Note:
- Use Outbound Messaging to handle integration solutions when possible.
- Use callouts to third-party Web services only when necessary.
To generate an Apex class from a WSDL:
1. In the application, click Your Name ➤ Setup ➤ Develop ➤ Apex Classes.
2. Click Generate from WSDL.
3. Click Browse to navigate to a WSDL document on your local hard drive or network, or type in
the full path. This WSDL document is the basis for the Apex class you are creating.
Note:
- The WSDL document that you specify might contain a SOAP endpoint location that references
an outbound port.
- For security reasons, Salesforce restricts the outbound ports you may specify to one of the
following:
- 80: This port only accepts HTTP connections.
- 443: This port only accepts HTTPS connections.
- 1024–66535 (inclusive): These ports accept HTTP or HTTPS connections.
4. Click Parse WSDL to verify the WSDL document contents.
- The application generates a default class name for each namespace in the WSDL document
and reports any errors.
- Parsing will fail if the WSDL contains schema types or schema constructs that are not
supported by Apex classes, or if the resulting classes exceed 1 million character limit on Apex
classes.
- For example, the Salesforce SOAP API WSDL cannot be parsed.
5. Modify the class names as desired.
- While you can save more than one WSDL namespace into a single class by using the same class
name for each namespace, Apex classes can be no more than 1 million characters total.
6. Click Generate Apex.
- The final page of the wizard shows which classes were successfully generated, along with any
errors from other classes.
- The page also provides a link to view successfully-generated code.
* The successfully-generated Apex class includes stub and type classes for calling the third-party
Web service represented by the WSDL document.
* These classes allow you to call the external Web service from Apex.
Note the following about the generated Apex:
* If a WSDL document contains an Apex reserved word, the word is appended with _x when the
Apex class is generated.
* For example, limit in a WSDL document converts to limit_x in the generated Apex class.
* If an operation in the WSDL has an output message with more than one element, the
generated Apex wraps the elements in an inner class.
* The Apex method that represents the WSDL operation returns the inner class instead of the
individual elements.
* After you have generated a class from the WSDL, you can invoke the external service
referenced by the WSDL.
How to run generated class from WSDL
BookrWs.BookWs stub = new BookrWs.BookWs();//Top level class name.Inner level class
name

stub.sessionHeader = new BookrWs.sessionHeader_Element();

stub.sessionHeader.sessionID = userInfo.getSessionID();

stub.insertBook('SOAP19','VASU',1000);

Más contenido relacionado

Destacado

Integrating The Cloud - How to integrate Salesforce
Integrating The Cloud  - How to integrate SalesforceIntegrating The Cloud  - How to integrate Salesforce
Integrating The Cloud - How to integrate SalesforceRoy Gilad
 
Secure Salesforce: External App Integrations
Secure Salesforce: External App IntegrationsSecure Salesforce: External App Integrations
Secure Salesforce: External App IntegrationsSalesforce Developers
 
Webservices in SalesForce (part 1)
Webservices in SalesForce (part 1)Webservices in SalesForce (part 1)
Webservices in SalesForce (part 1)Mindfire Solutions
 
AI is the New UI - Tech Vision 2017 Trend 1
AI is the New UI - Tech Vision 2017 Trend 1AI is the New UI - Tech Vision 2017 Trend 1
AI is the New UI - Tech Vision 2017 Trend 1Accenture Technology
 
What Makes Great Infographics
What Makes Great InfographicsWhat Makes Great Infographics
What Makes Great InfographicsSlideShare
 
Masters of SlideShare
Masters of SlideShareMasters of SlideShare
Masters of SlideShareKapost
 
STOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
STOP! VIEW THIS! 10-Step Checklist When Uploading to SlideshareSTOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
STOP! VIEW THIS! 10-Step Checklist When Uploading to SlideshareEmpowered Presentations
 
10 Ways to Win at SlideShare SEO & Presentation Optimization
10 Ways to Win at SlideShare SEO & Presentation Optimization10 Ways to Win at SlideShare SEO & Presentation Optimization
10 Ways to Win at SlideShare SEO & Presentation OptimizationOneupweb
 
How To Get More From SlideShare - Super-Simple Tips For Content Marketing
How To Get More From SlideShare - Super-Simple Tips For Content MarketingHow To Get More From SlideShare - Super-Simple Tips For Content Marketing
How To Get More From SlideShare - Super-Simple Tips For Content MarketingContent Marketing Institute
 
How to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & TricksHow to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & TricksSlideShare
 

Destacado (15)

Using Apex for REST Integration
Using Apex for REST IntegrationUsing Apex for REST Integration
Using Apex for REST Integration
 
SalesForce WebServices part 2
SalesForce WebServices part 2SalesForce WebServices part 2
SalesForce WebServices part 2
 
Integrating The Cloud - How to integrate Salesforce
Integrating The Cloud  - How to integrate SalesforceIntegrating The Cloud  - How to integrate Salesforce
Integrating The Cloud - How to integrate Salesforce
 
Secure Salesforce: External App Integrations
Secure Salesforce: External App IntegrationsSecure Salesforce: External App Integrations
Secure Salesforce: External App Integrations
 
Exploring the Salesforce REST API
Exploring the Salesforce REST APIExploring the Salesforce REST API
Exploring the Salesforce REST API
 
Webservices in SalesForce (part 1)
Webservices in SalesForce (part 1)Webservices in SalesForce (part 1)
Webservices in SalesForce (part 1)
 
AI is the New UI - Tech Vision 2017 Trend 1
AI is the New UI - Tech Vision 2017 Trend 1AI is the New UI - Tech Vision 2017 Trend 1
AI is the New UI - Tech Vision 2017 Trend 1
 
What Makes Great Infographics
What Makes Great InfographicsWhat Makes Great Infographics
What Makes Great Infographics
 
Build Features, Not Apps
Build Features, Not AppsBuild Features, Not Apps
Build Features, Not Apps
 
Masters of SlideShare
Masters of SlideShareMasters of SlideShare
Masters of SlideShare
 
STOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
STOP! VIEW THIS! 10-Step Checklist When Uploading to SlideshareSTOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
STOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
 
You Suck At PowerPoint!
You Suck At PowerPoint!You Suck At PowerPoint!
You Suck At PowerPoint!
 
10 Ways to Win at SlideShare SEO & Presentation Optimization
10 Ways to Win at SlideShare SEO & Presentation Optimization10 Ways to Win at SlideShare SEO & Presentation Optimization
10 Ways to Win at SlideShare SEO & Presentation Optimization
 
How To Get More From SlideShare - Super-Simple Tips For Content Marketing
How To Get More From SlideShare - Super-Simple Tips For Content MarketingHow To Get More From SlideShare - Super-Simple Tips For Content Marketing
How To Get More From SlideShare - Super-Simple Tips For Content Marketing
 
How to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & TricksHow to Make Awesome SlideShares: Tips & Tricks
How to Make Awesome SlideShares: Tips & Tricks
 

Más de mallareddy0107

Más de mallareddy0107 (10)

Approval process
Approval processApproval process
Approval process
 
Interview questions
Interview questionsInterview questions
Interview questions
 
Interview questions
Interview   questionsInterview   questions
Interview questions
 
Hr interview
Hr interviewHr interview
Hr interview
 
Governor limits
Governor limitsGovernor limits
Governor limits
 
Data migration
Data migrationData migration
Data migration
 
Coding standards
Coding standardsCoding standards
Coding standards
 
Sfdc Knowledge
Sfdc KnowledgeSfdc Knowledge
Sfdc Knowledge
 
Approvals and workflow in salesforce
Approvals and workflow in salesforceApprovals and workflow in salesforce
Approvals and workflow in salesforce
 
Approval process
Approval processApproval process
Approval process
 

Invoking callouts using apex

  • 1. Invoking Callouts Using Apex Invoking Callouts Using Apex * An Apex callout enables you to tightly integrate your Apex with an external service by making a call to an external Web service or sending a HTTP request from an Apex script and then receiving the response. Tightly Couple Architecture * Apex provides integration with Web services that utilize SOAP and WSDL, or HTTP services (RESTful services). Note: Note: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. * Callouts enable Apex to invoke external web or HTTP services. *Apex Web services allow an external application to invoke Apex methods through Web services. Adding Remote Site Settings
  • 2. To add a remote site setting: 1. Click Your Name ➤ Setup ➤ Security Controls ➤ Remote Site Settings. 2. Click New Remote Site. 3. Enter a descriptive term for the Remote Site Name. 4. Enter the URL for the remote site. 5. Optionally, enter a description of the site. 6. Click Save. Types of WSDL's 1. Enterprise WSDL * It is a big WSDL which contains information about schema of organization. * Strictly Typed: For Integer if we give 3.19 like that then it will not accept and throw error. * When schema is modified then we have to recreate new enterprise WSDL. 2. Partner WSDL * Loosly Typed: For Integer if we give 3.19 like that then it will accept and not throw error. * When schema is modified then it will automatically updated. SOAP Services: Defining a Class from a WSDL Document * Classes can be automatically generated from a WSDL document that is stored on a local hard drive or network. * Creating a class by consuming a WSDL document allows developers to make callouts to the external Web service in their Apex scripts. Note: - Use Outbound Messaging to handle integration solutions when possible. - Use callouts to third-party Web services only when necessary. To generate an Apex class from a WSDL: 1. In the application, click Your Name ➤ Setup ➤ Develop ➤ Apex Classes. 2. Click Generate from WSDL. 3. Click Browse to navigate to a WSDL document on your local hard drive or network, or type in the full path. This WSDL document is the basis for the Apex class you are creating.
  • 3. Note: - The WSDL document that you specify might contain a SOAP endpoint location that references an outbound port. - For security reasons, Salesforce restricts the outbound ports you may specify to one of the following: - 80: This port only accepts HTTP connections. - 443: This port only accepts HTTPS connections. - 1024–66535 (inclusive): These ports accept HTTP or HTTPS connections. 4. Click Parse WSDL to verify the WSDL document contents. - The application generates a default class name for each namespace in the WSDL document and reports any errors. - Parsing will fail if the WSDL contains schema types or schema constructs that are not supported by Apex classes, or if the resulting classes exceed 1 million character limit on Apex classes. - For example, the Salesforce SOAP API WSDL cannot be parsed. 5. Modify the class names as desired. - While you can save more than one WSDL namespace into a single class by using the same class name for each namespace, Apex classes can be no more than 1 million characters total. 6. Click Generate Apex. - The final page of the wizard shows which classes were successfully generated, along with any errors from other classes. - The page also provides a link to view successfully-generated code. * The successfully-generated Apex class includes stub and type classes for calling the third-party Web service represented by the WSDL document. * These classes allow you to call the external Web service from Apex. Note the following about the generated Apex: * If a WSDL document contains an Apex reserved word, the word is appended with _x when the Apex class is generated. * For example, limit in a WSDL document converts to limit_x in the generated Apex class.
  • 4. * If an operation in the WSDL has an output message with more than one element, the generated Apex wraps the elements in an inner class. * The Apex method that represents the WSDL operation returns the inner class instead of the individual elements. * After you have generated a class from the WSDL, you can invoke the external service referenced by the WSDL. How to run generated class from WSDL BookrWs.BookWs stub = new BookrWs.BookWs();//Top level class name.Inner level class name stub.sessionHeader = new BookrWs.sessionHeader_Element(); stub.sessionHeader.sessionID = userInfo.getSessionID(); stub.insertBook('SOAP19','VASU',1000);