+ Start a Discussion
Love SFDCLove SFDC 

Requiredness on the WSDL elements generated from apex code

How to tag mandatory fields as minOccurs = "1" in the custom WSDL file that's generated from Apex class. Thanks in advance.
Ansh CoderAnsh Coder
Use this code to check whether a field is required or not.
Schema.DescribeSObjectResult r = systemObjectType.getDescribe();
            Map<String,Schema.SObjectField> M = r.fields.getMap();
            for(String fieldName : M.keySet())
            { 
                Schema.SObjectField field = M.get(fieldName);
                Schema.DescribeFieldResult F = field.getDescribe();
               //A nillable field can have empty content. A isNillable Boolean non-nillable field must have a value for the object to be                       //created or saved. 
              // if F.isNillable() is false then field is mandatory
              Boolean isFieldreq  = F.isNillable()

 
Love SFDCLove SFDC
Thanks for the response Anand. My question around generated the WSDL with an attribute tagged as required. Meaning-
If the class is like below:
global class example{
  webservice string myName ;
}

generated WSDL file has to look like

<xsd:element name="myName" minOccurs="1" type="xsd:string" nillable="false"/>

My ask is same as in this post https://developer.salesforce.com/forums/?id=906F0000000940YIAQ

Appreciate the help.