1

I have a apex webservice with "data structure" made of webService attributes.

In request data, i have:

global class GetRequestData{
    webService Date From;
    webService Date To;
    webService String Id;
}

When i send request over SoapUI, and will leave "To" empty, it will return '' is not a valid value for the type xsd:date so i want to make this field optional.

        <cas:Data>
           <cas1:From>2018-02-09</cas1:FromDate>
           <cas1:To></cas1:ToDate>
           <cas1:Id>23411</cas1:UseCaseId>
        </cas:Data>

I even tried to do soemthing like this, but since its not null, but its empty string, its not working.

            if(request.Data.To != null) {
                toDate = String.valueOf(request.Data.To);
            } else {
                Date today = Date.today();
                toDate = String.valueOf(today);
            }

So my question is, how to make webService attribute in request data optional, and how its possible to check condition, if Date field is not filled, so its not null.

Thank you in advance for any advice.

  • Make it as string and check in your apex code? – Pranay Jaiswal Nov 23 '18 at 12:19
2

In request data, i have:

No, you do not. From is a reserved keyword. If you were trying to use this code, it should not compile.

When i send request over SoapUI, and will leave "To" empty, it will return '' is not a valid value for the type xsd:date so i want to make this field optional.

To pass in a null value, you need to tell the server it is a null value.

    <cas:data xmlns:xsl="http://www.w3.org/2001/XMLSchema-instance">
       <cas1:FromDate>2018-02-09</cas1:FromDate>
       <cas1:ToDate xsl:nil="true" />
       <cas1:UseCaseId>23411</cas1:UseCaseId>
    </cas:data>

Please note that XML data is cAsE-sEnSiTiVe. The values above will work only if your variables are named correctly, and you observe the correct case, and everything else above is perfectly correct.

Alternatively, you can also omit the element entirely:

    <cas:data>
       <cas1:FromDate>2018-02-09</cas1:FromDate>
       <cas1:UseCaseId>23411</cas1:UseCaseId>
    </cas:data>

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.