Creating a custom Webservice, can I set the parameters of the webservice in such way that when I export the WSDL from SFDC such parameters result mandatory.

That mean that when someone try to call my webservice, the system automatically verify if all the mandatory fields are present and different from null in the soap call without the necessity to add apex validation logic.

thnks in advance. Klodjan

1 Answer 1


Salesforce Convention in WSDL for Required Elements. It has been Salesforce's convention when exposing its own Web Services and those built via Apex to expose each child element of a given XML structure, be that derived from an Object or an Apex class, without consideration for it being required (typically denoted in XML Schema via minOccurs="1", the default if not specified) or optional.

Salesforce use of minOccurs in XML Schema and why?. Salesforce explicitly outputs minOccurs="0" for every child element, regardless if it maps to a required field on an Object for example. Meaning that web service clients cannot enforce client side the need for required information, which is a shame, as this would be a good client side optimisation and make your web service API's more self describing. However the reasoning i imagine behind this, is to allow records to be updated and/or created with only specific fields to be specified. Thus if they made the XML Schema enforce required fields they would not be able to support this convention, which can be quite useful.

<xsd:complexType name="Test__c">
        <xsd:extension base="tns:sObject">
                <xsd:element name="A_Number__c" minOccurs="0" type="xsd:double" nillable="true"/>

enter image description here

Implementing required field validation without Apex code. If your using any of the Salesforce standard API's (Enterprise, Partner or REST) eventually the platform will enforce the 'required' field attribute on the field definition giving you an error, all be it only after the database operation has been attempted. Likewise if you write an Apex Web Service and it receives an SObject structure, it is only after you have attempted to perform DML (Database Manipulation Language) will an exception occur. In all but, Lookup Field types, you can configure this on a field. If you need something more custom before the database is hit, you will need to implement this yourself in your Apex code.

  • As you mentioned if we need to implement this validation before it hits database,we need to handle it in Apex code.Can you pass some reference to understand it in detail.Thanks
    – user10727
    Aug 21, 2014 at 11:48
  • Hi, sure happy to give more detail, but i'm not 100% sure what your asking about? Can you elaborate more on what you want to know please? Aug 21, 2014 at 13:12
  • sorry I forgot it was replied in 2013 :) my question is related to your answer that you gave for this post. :D...THis is what i was referring to :--- the last statement,from your earlier answer which i want to know more about "If you need something more custom before the database is hit, you will need to implement this yourself in your Apex code." <---so to handled in Apex code, do we have any pre-built classes in Apex to help us out with XML/JSON parsing.? Any reference that you could share.Thanks
    – user10727
    Aug 21, 2014 at 13:41
  • 1
    Ah i see what you mean now, yep there is native Apex support for both JSON and XML. Search the dev guide for these keywords, salesforce.com/us/developer/docs/apexcode/index_Left.htm Aug 22, 2014 at 9:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .