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
Arnold Joseph TodasArnold Joseph Todas 

Duplication of website

How can i ignore the www. for not showing an error example (www.yahoo.com = yahoo.com; www.cs.org != www.cs.ph)
here is duplication method for my website. Thanks in advance

public static void checkDuplicateWebsite(List<Account> newRecord){
       for(Account a: newRecord){
           List<Account> account = [SELECT Id, Website FROM Account WHERE Website=:a.Website];
           if(account.size()>0){
               a.adderror('You cannot create a duplicate Website');
           }       
    }
Shaijan ThomasShaijan Thomas
One suggestion : Remove SOQL from loop
I think to remove WWW use substring. Before using convert to string.
Thanks
Shaijan
Arnold Joseph TodasArnold Joseph Todas
@Shaijan Thomas
How can i put substring in if else statement?
sorry im newbie here
AJ
Ankit Maini.Ankit Maini.

You can use String methods such as replace

eg:

String url = a.Website;
url = url.replace('www.','');

  List<Account> account = [SELECT Id, Website FROM Account WHERE Website=:url];

And @Shaijan is right remove SOQL from the loop.

Thanks
Ankit Maini
Arnold Joseph TodasArnold Joseph Todas
I got an erro when on a.website here is my code :
public static void checkDuplicateWebsite(List<Account> newRecord){
       String url = a.Website;
       url = url.replace('www.','');
       List<Account> account = [SELECT Id, Website FROM Account WHERE Website=: url];    
       for(Account a: newRecord){
           if(account.size()>0){
               a.adderror('You cannot create a duplicate Website');
           }         
         } 
       }
Thanks For Help!
AJ
 
Ankit Maini.Ankit Maini.
HI AJ,

Try now
public static void checkDuplicateWebsite(List<Account> newRecord){
      for(Account a: newRecord){
       String url = a.Website;
       url = url.replace('www.','');
       List<Account> account = [SELECT Id, Website FROM Account WHERE Website=: url];    
           if(account.size()>0){
               a.adderror('You cannot create a duplicate Website');
           }         
         } 
       }

 
Arnold Joseph TodasArnold Joseph Todas
@Ankit Maini
Thanks it works. but how can i ignore the www. when adding an account website? 

Thanks for help!
AJ
Shaijan ThomasShaijan Thomas
list<string> urlList = new list<string>();
      for(Account a: newRecord)
      {
         if (a.Website != null)
         	urlList.add((a.Website).replace('www.','')); 
      }
      for(Account b : [SELECT Id, Website FROM Account WHERE Website in : urlList])
      {
               b.adderror('You cannot create a duplicate Website');         
      }

try this
Thanks
Shaijan
Arnold Joseph TodasArnold Joseph Todas
@Shaijan Thomas

The code don't have any error but the validation is not working. when i create a account with a website of 'www.fb.com' and i created another account with 'fb.com' it should show a error message.

Thanks for Help!
AJ
Shaijan ThomasShaijan Thomas
//just try this not sure
	Map<string, Account> urlList = new map<string, Account>();
      for(Account a: newRecord)
      {
         if (a.Website != null)
         {
             string d = (a.Website).replace('www.','');
             urlList.put(d,a); 
         }
         	
      }
	if (!urlList.isEmpty())
      for(Account b : [SELECT Id, Website FROM Account WHERE Website in : urlList.keyset()])
      {
          	account e = urlList.get(b.Website);
              e.adderror('You cannot create a duplicate Website');                
      }

Thanks
Shaijan
Arnold Joseph TodasArnold Joseph Todas
@Shaijan Thomas

The validation doesnt work. 

Thanks for Help!
AJ
Arnold Joseph TodasArnold Joseph Todas
@Shaijan Thomas

Sir Shaijan in your code.. when i create an account with 'www.google.com' and i created another account with 'www.google.com' its not showing any error. I think that's the missing. how can i fix the code for that thanks

Thank you for help!
AJ
Shaijan ThomasShaijan Thomas
urlList.put(a.Website,a); --> add this line after line 8 and Try
Thanks
Shaijan
Arnold Joseph TodasArnold Joseph Todas
@Ankit Maini

Your code work when i create an account with 'google.com' then i created another account with 'www.google.com' it shows an alert message but when add in vice versa it doesn't show an error and add. 

Thanks
AJ
Arnold Joseph TodasArnold Joseph Todas
@Shaijan Thomas

Sir Shaijan it doesn't work too

Thanks
AJ
Ankit Maini.Ankit Maini.
Hi @Arnold

As per your comment:
@Ankit Maini
Thanks it works. but how can i ignore the www. when adding an account website?

You have to create a trigger for it and remove the WWW from url everytime it insert or update and that will solve your problem.
DevOps Training 9DevOps Training 9

When i am applying for Google Ads i am facing the Issu like Duplicate Content so Duplicate Content of Duplicate Website is the Same Error?

Here is the Link of my Website : https://serialgossip.in/

david traskdavid trask
Redirect all the versions of your website to single one. Same like this https://bestbeardtrimmer2021.com/best-beard-trimmer-for-long-beard-2021/
open basketball guideopen basketball guide
redirection 301 will help you in this as this website has done the same outdoorbasketballguide.com
Eagle ApkEagle Apk
Redirect all the versions of your website to a single one. Same like this https://eagleapk.com/dead-target-mod-apk/
Reans KhansReans Khans
Can i find for my website : https://jannatasia.com/raw-cashews-bulk-supplier/ (https://jannatasia.com/raw-cashews-bulk-supplier/)?
Alex RanaAlex Rana
I also got this type of website here https://allgeneratorinfo.com/
William A. WalkerWilliam A. Walker
I want this type of site (https://quickricepuritytest.com/innocence-test/) can someone tell me the pattern of the website.
jeff Henderson 34jeff Henderson 34
All versions of your website should be redirected to one. Like this https://familysports.net/best-paintball-gun/
Frank ZelayaFrank Zelaya
I want a site like https://protigwelders.com/best-miller-tig-welder/ can someone help me.
Alex Smith 140Alex Smith 140
My website is not redirecting to one.  Can someone check? https://inshotapk.net/
Ajay SerialAjay Serial
Firstly you have to make sure that website should be open on one URL like mine TV serial written update (https://serialtalk.com/). And check there should be no redirection.
Pratiksha Patel 13Pratiksha Patel 13
Certainly! To modify the code to handle the website URL "https://heypune.com" and ignore the "www." prefix, you can use the following updated code:
public static void checkDuplicateWebsite(List<Account> newRecord){
    for(Account a: newRecord){
        String website = a.Website;
        
        // Remove "www." from the beginning of the website URL
        if(website.startsWith("www.")){
            website = website.substring(4);
        } else if(website.startsWith("https://www.")){
            website = "https://" + website.substring(12);
        } else if(website.startsWith("http://www.")){
            website = "http://" + website.substring(11);
        }
        
        List<Account> account = [SELECT Id, Website FROM Account WHERE Website = :website];
        
        if(account.size() > 0){
            a.addError('You cannot create a duplicate Website');
        }       
    }
}
In this updated code, we handle the case where the website URL starts with "https://www." or "http://www." as well. If the URL starts with either of these prefixes, we remove the corresponding number of characters (12 for "https://www." and 11 for "http://www.") from the URL. The remaining URL without the prefix is then used for the duplicate check.

By incorporating these additional checks, the code will correctly handle the provided website URL "https://heypune.com" and ignore the "www." prefix during the duplicate website check.
 
Louis KeithLouis Keith
Prevents duplicate Account creation by checking website URLs like https://reminilike.com/remini-mod-apk/ while ignoring "www." prefix. Uses a Set to track unique websites.