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
rickmerolerickmerole 

Breaking Entries with multiple lines into individual lines - not for the faint hearted!

I am on day one of my Group Edition subscription and am already hitting limits of the implementation.

What I am really trying to do, is to generate vCard files from my address book entries, so I can import them into my Mac address book. Yes, there is a free solution, but it doesn't work well, so I made my own. I'll write about that later (if anyone wants to see it).

Part of my solution is the need for a script that runs on my server, to take an http request and return a downloadable file (which is my vCard). Most fields have no special characters in them, EXCEPT the "Mailing Address" field of the "Contact Detail" page.

This field is auto-generated by salesforce and puts some fields together, including "Mailing Street". The latter may contain line feed characters (when you enter multiple lines of text in there, which is very likely).

The challenge now for me was to extract individual lines from either of these two fields, and that is where the pain began...

First I thought, the function BR() would generate the exact same kind of linefeed that would be stored in the field. Wrong. This means, using the FIND() function will not find line feeds.

However - using the MID() function on the end of line of a "Mailing Street" entry allowed me to extract the invisible character, and in turn to search for it using FIND().

Here is what I did. This is kludgy, but I have no alternative ideas.

In "Company Profile -> Company Information -> Address", I made sure to enter two lines of data. The second line is our suite number, "#150".

Now I created an invisible (i.e. not visible on any page layouts) text field "linefeed". The formula in it is:

MID( $Organization.Street , FIND("#150", $Organization.Street ) - 2, 1)

This extracts the first of the two(!) invisible line feed characters and stores it in the field

Next, I am assuming that an address field will not contain more than three lines, and I created the following fields (for simplicity I am only giving the API names here):

Mailing_Street_1__c = IF(FIND( linefeed__c , MailingStreet ) = 0, MailingStreet, LEFT( MailingStreet , FIND( linefeed__c , MailingStreet )-1))

Mailing_Street_1_len__c = LEN( Mailing_Street_1__c )

Mailing_Street_2__c = IF(Mailing_Street_2_len__c > 0, MID( MailingStreet , Mailing_Street_1_len__c + 3, Mailing_Street_2_len__c ) , "")

Mailing_Street_2_len__c = IF(FIND( linefeed__c , MailingStreet, Mailing_Street_1_len__c + 3) = 0, LEN( MailingStreet ) - Mailing_Street_1_len__c , FIND( linefeed__c , MailingStreet, Mailing_Street_1_len__c + 3) - Mailing_Street_1_len__c - 3)

Mailing_Street_3__c = RIGHT( MailingStreet , Mailing_Street_3_len__c - 4)

Mailing_Street_3_len__c = LEN( MailingStreet ) - Mailing_Street_2_len__c - Mailing_Street_1_len__c


the ...len__c are numerical formulas, the rest text.

Presto - now you have the address in three individual lines...!
chris_centrachris_centra

very nice.

chris