Concepts or coding lessons of Salesforce that you can implement easily

7 Easy Steps to Generate Apex Class From WSDL In Salesforce

Steps to generate an Apex class from a WSDL :

1. Take the external WSDL document and store in local computer or laptop.
2. Go to Setup -> Build -> Develop -> Apex Classes
3. Click on Generate from WSDL button.




4. Click on Choose File button and Select a WSDL document 
    which you stored into your system.
5. Click on Parse WSDL button.


The application generates a default class name for each namespace in the WSDL document and displays if there are any errors. If the WSDL contains schema types or constructs that doesn`t support by Salesforce Apex classes, or if the resulting classes exceed the 1 million character governor limit of Salesforce on Apex classes then Parsing fails . For example, Error will be like the Salesforce SOAP API WSDL cannot be parsed.

6. Modify the class names if you want. While you can save more than 1 WSDL namespace into a single apex class. To do this you have to use the same class name for each namespace, Apex classes can not contains more than 1 million characters total, as this is governoe limit of salesforce.

7. Click Generate Apex button. The final page of that wizard shows which classes were successfully generated from WSDL. It also contains errors if any from other apex classes. The page also provides a Salesforce link to view successfully generated apex classes.

Note: The size of any WSDL document can be at most 1MB. When the document is parsed to apex class, then each namespace becomes an Apex class.

Apex classes can be automatically generated from a WSDL document that is stored on a local hard disk or network. Creating an apex class by consuming a WSDL document allows developers to send callouts to the external Web service in their Apex code.

The WSDL file that you provide may contain a SOAP endpoint location that references an outbound port.

For security purpose, Salesforce restricts those 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.

Note the following about the generated Apex:


  • If a WSDL file contains an Apex reserved word, then while Apex class is generating that word is appended with _x. For example, a limit reserved word in a WSDL document converts to limit_x in the generated Apex class. Check out the Salesforce document to check details on of handling characters in element names in a WSDL that are not supported in Salesforce Apex variable names.
  • If any logic which is in the WSDL has an output message which has more than one element, then the generated Apex wraps the elements in an inner class. The Apex method that represents the WSDL logic returns the inner class instead of the individual elements.
  • Since periods that is (.) are not allowed in Apex class names, If any periods present in WSDL names used to generate Apex classes are replaced by underscores (_) in the generated Salesforce Apex code.
If you want more details then check WSDL documentation provided by Salesforce .

Enjoy! If you have any questions, comments etc. please feel free to let me know. As always, please feel free to get in touch me as I would be more than happy to assist you with any of your Salesforce development needs.

loading...

No comments:

Post a Comment