+ Start a Discussion
RovRov 

finding domain name from website

On the Account object I have created a formula field called Domain_Name__c . The formula I have used is this,

 

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

 

Where website is a standard field on Account.

 

If Website is www.xyzdomain.com or https://www.xyzdomain.com

 

In Domain_Name__c I expected result as xyzdomain.com

 

Instead i am getting the result either as

.xyzdomain.com or ww.xyzdomain.com depending on whether the Email entered was 'www.xyzdomain.com' or 'https://www.xyzdomain.com'


Any thoughts how I can only get the text after the .   

 

e.g If, in the field Website  I enter www.salesforce.com  or  https://www.salesforce.com the result in the Domain_Name__c should be salesforce.com 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
PremanathPremanath

So ok man remove __c and try it it's working fine

 

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

 

 

 

If it is helpful plz mark as solution for others it may benfit

All Answers

PremanathPremanath

Hi Try this,

it may helpful for you

 

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

 

 

If it helpful plz make it as solution for others it may benfit

prem

RovRov

Thanks for the response but that's the exact formula i have (see my original post).

On Account, the field website is a standard field.

PremanathPremanath

So ok man remove __c and try it it's working fine

 

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

 

 

 

If it is helpful plz mark as solution for others it may benfit

This was selected as the best answer
Eli StrongEli Strong
The 'best answer' works great IF there is a "www." to start the website. In the case that the website is http://abcd.com or just abcd.com, it only returns '.com'. I needed a way to get the domain from the website regardless of how it starts.

I found this formula:

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 )))

But that doesn't work for websites that start with 'http://www.' I made some adjustments to the formula by adding more IF statements and finally ended up with this.

IF(BEGINS(Website, "http://www"), SUBSTITUTE(Website, LEFT(Website, FIND(".", Website)), NULL),
IF(BEGINS(Website, "https://www"), SUBSTITUTE(Website, LEFT(Website, FIND(".", Website)), NULL),
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)))))

Now if I could only figure out a way to build onto this to remove everything AFTER '.com' or '.org'.
 
Peter BittingerPeter Bittinger
To follow on to Eli's post, this formula will do the above, plus remove everything after the .com/.net/.org.
This works on the acccount record.  It can be added to any other object by changing the 'Website' to the field name containing the URL

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)))
 
Walter PelowskiWalter Pelowski
I came across this thread when trying to set this up for my own org.

Peter, I tried your function but it didn't trim the "www." in the cases where the website just began with a "www."

I ended up doing a hybrid of Eli's function, but to make it WAY more readable and maintainable, I created an intermediate custom formula field named, "Domain Name and Path".

Domain Name and Path Function
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
                )
        )
)
Domain Name Function
IF(FIND("/", Domain_Name_and_Path__c)>0, LOWER(LEFT(Domain_Name_and_Path__c, FIND("/", Domain_Name_and_Path__c) - 1)), LOWER(Domain_Name_and_Path__c))

Additional Notes
  1. I combined a few of the IF statements from Eli's function together otherwise you run out of characters in the master Domain Name function.
  2. Since the spaces don't affect the character count, I tabbed it out a little to make it more obvious where each IF statement begins and ends.
  3. Thankfully after the combination of IF functions, you can even add another IF at the beginning if there are certain domains (liked LinkedIn URLs) that you want to exclude from the list because they don't represent the actual company's domain.  (Obviously you can also just bulk clean-up the data.)
  4. I chose to return the domain name in Lower Case in the Domain Name function, but feel free to remove that if you wish.
  5. This all would've been a heck of a lot easier if Regular Expressions were supported in Custom Formula Fields, but alas they are not (https://developer.salesforce.com/page/An_Introduction_to_Formulas).
Jen StretchJen Stretch
I realize this thread is very old, but I'm wondering is someone can help me modify the formula to remove the trailing slash at the end of a website URL. I am using the formula in the best answer: SUBSTITUTE(Website, LEFT(Website, FIND(".", Website)), NULL)

But, if my website is www.google.com/ I would like my formula to disregard the trailing slash at the end and only display:  google.com

Any insight is appreciated!
 
Walter PelowskiWalter Pelowski
Jen, if you create the two functions I have listed above, you can get a domain name without a trailing slash.  I opt to also remove the
http://www.
and
https://www.
from the prefix.  You can alter the first function if you'd like if you want to keep that.


The nice thing is with the two functions working together I can have
https://www.salesforce.com
just return to me
salesforce.com
which is what I want, especially when trying to match people to accounts or have another field for determining uniqueness for accounts.

The other route that you can go here is to use the Data Loader, or DemandTools to search for trailing slashes and just remove them.
abhik dey 1abhik dey 1
Based on the above rules, I am able to get the domain from the website like 'http://www.google.com'  to google.com.
But I need a generic way to extract only google after we got google.com because in my case the account will have different website not specific to .com it can be lot of varities.
To get google.com from http://www.ggogle.com i have used the below if condition which takes care for both https or only www.

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
                )
        )
)

Any help appreciated !
Walter PelowskiWalter Pelowski
I think if you want to break it down any further, you're going to want likely use workflow rule/field updates to store a calculated value (like the domain name) into a field and then run a simple formula on that.  Otherwise, you end up with a much larger formula that's harder to understand or you run out of space like you see here (https://www.screencast.com/t/I1d2dbh38S).

A basic formula for getting this once you have the domain would be
IF(FIND(".", Domain_Name__c)>0, LEFT(Domain_Name__c, FIND(".", Domain_Name__c) - 1), Domain_Name__c)
but this assumes the important part is at the beginning.  What do you would consider the relevant part of the domain?  It might not always be the first part.  If an email address or website has a subdomain like
  1. engineering.google.com
  2. hr.international.microsoft.com
  3. math.schoolname.k12.mi.us
how are you going to determine which is the important part?  You can't even try to pick out the Top Level Domain like .com, .edu, .net because there are a ton of those (https://www.icann.org/resources/pages/tlds-2012-02-25-en) and sometimes an additional prefix comes before the TLD.  So until we can run a series of regexs on some data, I just don't know how you can clean it up enough to get the unique data you'll want to return.

For the standard examples though where it's basically
domainname.tld
I'd suggest you run some workflow rules/field updates to store a temporary/auto-updating value for the domain name and then run the basic function I have listed above.
abhik dey 1abhik dey 1
Thanks for your reply. Yes I agree with you; in a single formula, it will be difficult to store and then do a calculated logic on the stored value again. I have breakdown to two different values in different fields to get the desired output. Appreciate your help!
Arnold F BrownArnold F Brown

Found a formula that solves for www, http://, and https:// prefixes... good stuff!

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 )))

Here's the post I got it from: https://salesforce.stackexchange.com/a/68812

Aykut Parlak 5Aykut Parlak 5
I set a formula which solves my issue also for url with a pattern xxxx.domain.com/yyy:

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))

Here is the my comment there: 
https://salesforce.stackexchange.com/a/287651/65402
Enrique MuñozEnrique Muñoz
Thanks @Walter Pelowski!!!
Inderdeep Singh 68Inderdeep Singh 68