5

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?

2 Answers 2

5

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

1

You can use methods like these: a.ShippingAddress.getCity();

All the Address methods are shown here: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_system_Address.htm

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .