
@Future(callout=true)
public static void callPostAdressAPI(Id contactId) {
/*
@contactId - Id of the contact to be sent for Verification API.
*/
System.debug('ContactVerificationAPICaller.callPostAddressAPI started.');
try {
List<Contact> listContact = [
select
Id,
Postal_Address__c,
Postal_Address_Country__c,
PostalDPID__c,
Postal_Address_Postcode__c,
Postal_Address_State__c,
Postal_Address_Suburb__c,
Postal_Address_Invalid__c
from Contact
where id = :contactId];
if (listContact.size() == 1 ) {
// Object of the action.
Contact contactResult = listContact[0];
String PostalDPID,Dpidvalue;
System.debug('contactResult.Postal_Address_Suburb__ccontactResult.Postal_Address_Suburb__c'+contactResult.Postal_Address_Suburb__c);
System.debug('contactResult.Postal_Address_State__ccontactResult.Postal_Address_State__c'+contactResult.Postal_Address_State__c);
System.debug('contactResult.Postal_Address_Postcode__ccontactResult.Postal_Address_Postcode__c'+contactResult.Postal_Address_Postcode__c);
System.debug('contactResult.Postal_Address__ccontactResult.Postal_Address__c'+contactResult.Postal_Address__c);
String address1=contactResult.Postal_Address__c;
String address2=contactResult.Postal_Address_State__c+' '+contactResult.Postal_Address_Postcode__c;
String address3=null;
System.debug('Address 1 :'+address1);
System.debug('Address 2 :'+address2);
System.debug('Address 3 :'+address3);
String serviceURL='http://158.69.22.39:8001/addressValidator/AddressValidation/Address?username=mule&password=mule&address1='+address1+'&address2='+address2+'&address3='+address3;
Http httpClient=new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(serviceURL);
req.setMethod('POST');
req.setHeader('Content-Type', 'multipart/form-data');
req.setBody(' ');
HttpResponse res = httpClient.send(req);
System.debug('Response : '+res.getBody());
String soapResponse = res.getBody();
DPIDParser cls=new DPIDParser();
DPIDParser parsedResponse =cls.parse(soapResponse);
if(parsedResponse != null) {
PostalDPID = parsedResponse.DPID;
contactResult.PostalDPID__c = PostalDPID;
}
if(PostalDPID == '' || PostalDPID == ' ' ) {
contactResult.Postal_Address_Invalid__c= true;
} else {
contactResult.Postal_Address_Invalid__c= false;
}
update contactResult;
}
}catch (Exception ex){
System.debug(ex);
}
System.debug('ContactVerificationAPICaller.callPostAdressAPI finished.');
}

USER_DEBUG|[173]|DEBUG|Response : {"Postcode":"2251","State":"NSW","Address2":"NSW2251","Address1":"4THEGLADE","DPID":"00000000","Suburb":""}