3

is there a way to set maxLength value for String variables exposed through my custom soap web service?

global class MySoapService {
  webService String myName;
  ...
}

Let's say I would need to limit myName variable to accept only max 10 charactes. How would I manage to do this?

  • There is a soap header named AllowFieldTruncationHeader, which defines behavior for too long String fields (link to documentation: salesforce.com/developer/docs/api/Content/…). But that header is controlled by web service client, so it isn't very helpful. Usually I create request validation class, which contains my validation logic, when request is invalid I throw an exception with message on what's wrong. – mischczu May 3 '15 at 20:06
1

Based on some now deleted answers and comments, the question is how to communicate to consumers of the WSDL what the maximum allowed length of a string parameter is.

In XML Schema used within WSDL, the idea of restrictions is used to limit acceptable values of existing types. Here is an example for for the length of a string Is it possible to require min and max string length for param in wsdl file?.

(Enforcement of these restrictions is not implemented in all frameworks - for example Axis 1.x did not enforce them.)

There is no annotation in Apex to add the maxLength value to your class, so in theory you would have to take the WSDL generated from your class, manually modify it, then generate Apex from it using "Generate from WSDL" (AKA wsdl2apex). But the generator does not support this pattern - see Empty sub-classes in output of wsdl2apex?? - so that won't work.

In short, your approach does not look possible in Salesforce.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.