1

I am trying to get the capture just the domain name from a website field in Account in a formula field.

For eg.

if website is http://www.yahoo.com i need the formula field to display only yahoo. this should work if the website is put in as http://yahoo.com. Or if the url is https://na9.salesforce.com it should be salesforce

SUBSTITUTE(Website , LEFT(Website , FIND(".", Website )), NULL)

5 Answers 5

1

There are lots of different cases that you need to work through. Here is the complete formula that worked for us:

SUBSTITUTE(
    IF(
        FIND(
            "/",
            IF(
                FIND("www.", Website) > 0,
                IF(
                    FIND("//", Website) > 0,
                    SUBSTITUTE(Website, LEFT(Website, FIND("//www.", Website) + 5), NULL),
                    Website
                ),
                IF(
                    FIND("//", Website) > 0,
                    SUBSTITUTE(Website, LEFT(Website, FIND("//", Website) + 1), NULL),
                    Website
                )
            )
        ) > 0, 
        LEFT(
            IF(
                FIND("www.", Website) > 0,
                IF(
                    FIND("//", Website) > 0,
                    SUBSTITUTE(Website, LEFT(Website, FIND("//www.",Website) + 5), NULL),
                    Website
                ),
                IF(
                    FIND("//", Website) > 0,
                    SUBSTITUTE(Website, LEFT(Website, FIND("//",Website) + 1), NULL),
                    Website
                )
            ),
            FIND(
                "/",
                IF(
                    FIND("www.", Website) > 0,
                    IF(
                        FIND("//", Website) > 0,
                        SUBSTITUTE(Website, LEFT(Website, FIND("//www.",Website) + 5), NULL),
                        Website
                    ),
                    IF(
                        FIND("//", Website) > 0,
                        SUBSTITUTE(Website, LEFT(Website, FIND("//", Website) + 1), NULL),
                        Website
                    )
                )
            ) - 1
        ),
        IF(
            FIND("www.", Website) > 0,
            IF(
                FIND("//", Website) > 0,
                SUBSTITUTE(Website, LEFT(Website, FIND("//www.", Website) + 5), NULL),
                Website
            ),
            IF(
                FIND("//", Website) > 0,
                SUBSTITUTE(Website, LEFT(Website, FIND("//", Website) + 1), NULL),
                Website
            )
        )
    ),
    'www.', 
    ''
)
1

I had the same issue and this is how I solved it.

If(BEGINS(Website, "www."), MID(Website, FIND('www.', Website, 1)+4, (LEN(Website) - FIND('www.', Website, 1)+4)),

If(BEGINS(Website, "http://"), MID(Website, FIND('http://', Website, 1)+7, (LEN(Website) - FIND('http://', Website, 1)+7)),

IF(BEGINS(Website, "https://"), MID(Website, FIND('https://', Website, 1)+8, (LEN(Website) - FIND('https://', Website, 1)+8)), Website )))

1

I found there were additional variations in the URLs with some having www. and other without. Same code structure, but additional searches to further capture the name:

If(BEGINS(Website, "www."), MID(Website, FIND('www.', Website, 1)+4, (LEN(Website) - FIND('www.', Website, 1)+4)),

If(BEGINS(Website, "http://www."), MID(Website, FIND('http://www.', Website, 1)+11, (LEN(Website) - FIND('http://www.', Website, 1)+11)),

If(BEGINS(Website, "https://www."), MID(Website, FIND('https://www.', Website, 1)+12, (LEN(Website) - FIND('https://www.', Website, 1)+12)),

If(BEGINS(Website, "http://"), MID(Website, FIND('http://', Website, 1)+7, (LEN(Website) - FIND('http://', Website, 1)+7)),

If(BEGINS(Website, "https://"), MID(Website, FIND('https://', Website, 1)+8, (LEN(Website) - FIND('https://', Website, 1)+8)), Website )))))

1

This works for http://www.yahoo.com, http://yahoo.com,https://www.yahoo.com... and for http://www.yahoo.com/test1/test2 etc.

IF(FIND('/',SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(Website, 'http://', NULL), 'https://', NULL), 'www.', NULL))>0,LEFT(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(Website, 'http://', NULL), 'https://', NULL), 'www.', NULL),FIND('/',SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(Website, 'http://', NULL), 'https://', NULL), 'www.', NULL))-1),SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(Website, 'http://', NULL), 'https://', NULL), 'www.', NULL))
1
  • Works like a charm. you save my day thank you
    – Pavan tej
    Commented Nov 15, 2021 at 20:14
1

tried all the formulas provided as answers above. None of these seems to work. Found one in Salesforce help community which seems to work for me see url below. This was answered by Keiji Otsubo (Fukada Electric Co.,Ltd.)

pasting here for others:

left(
IF(OR(BEGINS(Website, "http://www"),BEGINS(Website, "https://www"), BEGINS(Website, "www.")),
    SUBSTITUTE(Website, LEFT(Website, FIND(".", Website)), NULL),
        IF(BEGINS(Website, "http://"),
            MID(Website, FIND('http://', Website, 1)+7, (LEN(Website) - FIND('http://', Website, 1)+7)),
                IF(BEGINS(Website, "https://"),
                    MID(Website, FIND('https://', Website, 1)+8, (LEN(Website) - FIND('https://', Website, 1)+8)),
                        Website
                )
        )
)
,FIND('.',
    IF(OR(BEGINS(Website, "http://www"),BEGINS(Website, "https://www"), BEGINS(Website, "www.")),
        SUBSTITUTE(Website, LEFT(Website, FIND(".", Website)), NULL),
            IF(BEGINS(Website, "http://"),
                MID(Website, FIND('http://', Website, 1)+7, (LEN(Website) - FIND('http://', Website, 1)+7)),
                    IF(BEGINS(Website, "https://"),
                        MID(Website, FIND('https://', Website, 1)+8, (LEN(Website) - FIND('https://', Website, 1)+8)),
                            Website
                    )
            )
    )
)-1)

https://trailhead.salesforce.com/trailblazer-community/feed/0D54S00000DcN3eSAF

You must log in to answer this question.

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