About Me

My photo
PLANO, Texas, United States

Saturday, May 18, 2013

WebService Fuctions

Apex Web Service

Apex class methods can be exposed as custom Force.com Web services API calls. This allows an external application to invoke an Apex web service to perform an action in Salesforce.com. Use the Webservice keyword to define these methods. For
Example:
global class MyWebService {
webService static Id makeContact(String lastName, Account a) {
Contact c = new Contact(lastName = 'Weissman', AccountId = a.Id);
insert c;
return c.id;
}
}
A developer of an external application can integrate with an Apex class containing webService methods by generating a WSDL for the class.To generate a WSDL from an Apex class detail page:
1. In the application navigate to Your Name  Setup  Develop  Apex Classes.
2. Click the name of a class that contains web Service methods.
3. Click Generate WSDL.

Considerations for Using the WebService Keyword:

  • You cannot use the webService keyword when defining a class. However, you can use it to define top-level, outer class methods, and methods of an inner class.
  • You cannot use the webService keyword to define an interface, or to define an interface's methods and variables.
  • System-defined enums cannot be used in Web service methods.
  • You cannot use the webService keyword in a trigger because you cannot define a method in a trigger.
  • All classes that contain methods defined with the webService keyword must be declared as global. If a method or inner class is declared as global, the outer, top-level class must also be defined as global.
  • Methods defined with the webService keyword are inherently global. These methods can be used by any Apex script that has access to the class. You can consider the webService keyword as a type of access modifier that enables more access than global.
  • You must define any method that uses the webService keyword as static.
  • You cannot deprecate web Service methods or variables in managed package code.
  • Because there are no SOAP analogs for certain Apex elements, methods defined with the webService keyword cannot take the following elements as  parameters.While these elements can be used within the method, they also cannot be marked as return values.
    • Maps
    • Sets
    • Pattern objects
    • Matcher objects
    • Exception objects
  • You must use the webService keyword with any member variables that you want to expose as part of a Web service. You should not mark these member variables as static.
  • Salesforce.com denies access to Web service and execute anonymous requests from an AppExchange package that has restricted access.
  • Apex classes and triggers saved (compiled) using API version 15.0 and higher produce a runtime error if you assign a String value that is too long for the field.
To know about other integration API at a glance, pls Click here
To know more about the security aspect of integration, pls Click here

No comments:

Post a Comment