+ 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