+ Start a Discussion
WilmerWilmer 

How to format a date value in a webservice callout?

Hi,

 

I'm working in an integration using call outs to external webservice and got a problem exchanging date values.

 

Look, in the webservice WSDL document the field is defined as: 

 

<element name="BIRTH_DAY" type="date"/>

I generated the apex class from its WSDL and now, when I try to consume the external webservice, I got an error because the other app is waiting the date value in format dd/MM/yyyy but Salesforce sends it like yyyy-MM-dd.

 

Is there any way to convert its format before we send the request?

 

Regards,

 

 

Wilmer

 

 

 

 

 

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
WilmerWilmer

Hi everyone,

 

Thanks for your time checking this case. 

 

I wanna share a workaround I found out:

 

 1. Go to the apex class generated from the WSDL.

 2. Look for the attribute name that receives the date value and change its datatype to string.

 3. In the class you're refering this attribute, use the method ".format()" to set the date to the dd/MM/yyyy format.

 

For example:

 

In the apex class generated from WSDL file...

 

//Generated by wsdl2apex

public class external_ws {

// some other code...

public class PERSON {
public String BIRTH_DAY; // Date BIRTH_DAY;
private String[] BIRTH_DAY_type_info = new String[]{'BIRTH_DAY','http://www.w3.org/2001/XMLSchema','date','1','1','false'};
}

 // some other code...

}

 Then, inside your implementation class:

 

external_ws.PERSON PersonData = new external_ws.PERSON(); PersonData.BIRTH_DAY = Account.PersonBirthdate.format();

 

 I hope this info helps everyone.

 

Best Regards,

 

Wilmer