function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

How to format a date value in a webservice callout?



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?















Best Answer chosen by Admin (Salesforce Developers) 

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','','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,