You need to sign in to do that
Don't have an account?
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:
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; } }
Please mark this answer as best answer if it helped to resolve your issue.
Thanks
Sandeep Singhal
http://www.codespokes.com/