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
Geeta VaddiGeeta Vaddi 

Help needed with Creating visualforce page to create 100 accounts with a button click

Hello Everyone,
I am new to salesforce and I am trying to get a salesforce internship. I was asked to solve and present the following excersice. Can someone tell me how to achieve this?

Create a visualforce page that will mass create 100 account records with a button click. Each account should randomly be assigned to a U.S. state. Visualforce page should then display the state distribution amongst all accounts visually in a table.

Extra Restrictions: Accounts can only have 5 states (business is only done in 5 states). Remove the accounts that are not in 1 of 5 states OR update those accounts with 1 of 5 states using a trigger.
Martha VMartha V
The visualforce page will display the table, but the custom controller will have all the logic to create the accounts. The controller gets called immideately when the VF page is invoked through the button.
controller -
make a list<string> variable with all the states in the US and if you want to change the account names, make an array for different names as well
create a for loop that will create the accounts taking names from one array and states from another. Once you have the 100 records then insert them.

You trigger should be a before insert trigger that will go through the list of Account records and change the states that do not comply with the organization and change them before inserting.

Add a button/link to the Account object (or wherever you want the button to be) that will call the VF page with a link.