[SalesForce] Serialize address field in apex

I have an address field which has some value and I need to convert address to string and store it in a text area field.

when i did

 String.valueof(a.ShippingAddress) 

its returning

system.Address[getCity=Columbia;getCountry=null;getCountryCode=null;getPostalCode=22036;getState=MD;getStateCode=null;getStreet=1505 21st Street NW;]

I just need to get the address as it appears in shipping address field. How can I serialise it to a string?

Best Answer

Though billing address appears as one field on the UI it is a compound of multiple text fields

You can do

account a = [select id,billingstreet,billingcity,billingstate,billingPostalCode,BillingCountry from account where id=:'001d000001hKINv'];
string shippingAddress = a.billingstreet+ a.billingcity + a.billingstate + a.billingPostalCode+ a.BillingCountry;

Refer: https://www.salesforce.com/developer/docs/api/Content/compound_fields_address.htm

Related Topic