[SalesForce] How to i split the address

I need to split the address using script. This is my input addresses

1 Avenue Descartes 92350 Le Plessis-Robinson FRANCE

My output like below:

Avenue Descartes
Le Plessis-Robinson 

Best Answer

You can use a specific identifier to split the custom address field into address components and store in proper address fields.

You should determine the identifier in your custom address field. Usually the identifier will be Comma(,).

Custom Address Field value = 1,Avenue Descartes,92350,Le Plessis-Robinson,FRANCE

In your apex method,

List<String> lstStringAddress = object.customField__c.split(',');
object.AddressField1 = lstStringAddress[0];
object.AddressField2 = lstStringAddress[1];
object.AddressField3 = lstStringAddress[2];
object.AddressField4 = lstStringAddress[3];
object.AddressField5 = lstStringAddress[4];

Hope it helps.

Related Topic