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
Kamil MieczakowskiKamil Mieczakowski 

For loop to update a website field for all Accounts

Hi All,

I am currently putting together an Apex script that would normalise all of the website addresses in our database by extracting the host addres and eliminating 'http', 'www' etc from the domain address. For this I am using a for loop. The problem that I am experiencing is that once the code runs (and it runs without errors and the debug produces the desired outcome) the website addresses don't get updated.

Here's the script so far:
public class Standardise_Websites {
    public Standardise_Websites(){
        list<Account> accts = [SELECT Website FROM Account];
               
        for (Account acct : accts){
            string website = acct.website;
            System.debug('Website is ---------->' +website);  
            website = website.replace('http://www.','');
            website = website.replace('https://www.','');
            website = website.replace('https://','');
            website = website.replace('http://','');
            website = website.replace('www.','');
            System.debug('Final website is ---------->' +website); 
            update acct;
            
        }
    update accts;
    }
}

               
    
Best Answer chosen by Kamil Mieczakowski
sandeep@Salesforcesandeep@Salesforce
Please use below code before code at line number 14.
acct.website = website;

Please mark this answer as best answer if it helped to resolve your issue. 

Thanks
Sandeep Singhal
http://www.codespokes.com/