Wednesday, July 20, 2011

Force.com Custom Web Services - How to create a SOAP fault

Question:

The standard salesforce.com web services defines fault and exception code when there is an error calling the services. Can I define my own fault code and exception code when writing my custom web services? If so, can you provide some samples? Thanks a lot.

Answer:

Using Apex, you cannot explicitly create your own SOAP faults. However, SOAP faults are automatically created when an Exception is thrown. So, to create your own SOAP fault, you simply throw an Exception.

Of course, Apex doesn't allow you to throw a standard exception, so you need to create your own custom exception class to throw an exception. This isn't very hard to do. Here is very simple code to create your own exception class:

public class SOAPException extends Exception {}

That is it.

To throw the exception, you simply write:

throw new SOAPException();

Salesforce.com provides plenty of documentation on how to create the classes and throw the exceptions. The biggest thing to remember is that the custom exception class must actually have the name Exception in it. Why, I don't know, but that is the way it is.

Here is a good starting point to the documentation on custom exception classes.
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_exception.htm

16 comments:

  1. Introduction of cloud servers have created a greatest impact over data interpretation. Also they made a history in cloud computing. Handling data made much easier and more comfortable like never before. Your content tells the same about the emerging technology. Thanks for sharing this information in here.

    Salesforce training in chennai | Salesforce admin training in chennai

    ReplyDelete
  2. Cloud servers are the best in safe guarding one's information thorugh online. Without this dedicated methodology many companies would have not existed at all. The same though has been furnished above. Thanks for sharing this worth while content in here. Keep writing article like this.

    Salesforce Training in Chennai | Salesforce training | Salesforce admin training in chennai

    ReplyDelete
  3. Very well written blog and I always love to read blogs like these because they offer very good information to readers with very less amount of words....thanks for sharing your info with us and keep sharing.

    angularjs Training in bangalore

    angularjs Training in bangalore

    angularjs interview questions and answers

    angularjs Training in marathahalli

    angularjs interview questions and answers

    angularjs-Training in pune

    ReplyDelete
  4. Want to make a big and interesting profit? best casino cities then come quickly to us.

    ReplyDelete
  5. It's interesting that many of the bloggers to helped clarify a few things for me as well as giving.Most of ideas can be nice content.The people to give them a good shake to get your point and across the command
    rpa training in bangalore
    best rpa training in bangalore
    rpa training in pune

    ReplyDelete
  6. i learned something new. Very well written. It was sooo good to read and usefull to improve knowledge.

    BEST ANGULAR JS TRAINING IN CHENNAI WITH PLACEMENT

    https://www.acte.in/angular-js-training-in-chennai
    https://www.acte.in/angular-js-training-in-annanagar
    https://www.acte.in/angular-js-training-in-omr
    https://www.acte.in/angular-js-training-in-porur
    https://www.acte.in/angular-js-training-in-tambaram
    https://www.acte.in/angular-js-training-in-velachery

    ReplyDelete
  7. This blog is the general information for the feature. You got a good work for these blog.We have a developing our creative content of this mind.could u share some more details.
    AngularJS training in chennai | AngularJS training in anna nagar | AngularJS training in omr | AngularJS training in porur | AngularJS training in tambaram | AngularJS training in velachery

    ReplyDelete
  8. It's interesting that many of the bloggers to helped clarify a few things for me as well as giving.Most of ideas can be nice content.The people to give them a good shake to get your point and across the command
    IELTS Coaching in chennai

    German Classes in Chennai

    GRE Coaching Classes in Chennai

    TOEFL Coaching in Chennai

    Spoken english classes in chennai | Communication training

    ReplyDelete
  9. I think Power BI and SOAP make use of the best utilities to solve some very complicated IT problems.


    Powerbi Read Soap

    ReplyDelete
  10. You've provided quite good information here. This is fantastic since it expands our knowledge and is also beneficial to us. Thank you for sharing this piece of writing. Website Development Tampa

    ReplyDelete