4

I would like to insert a bunch of sample account records (50 or so), without using the data loader. I have written code, but I do not know how to proceed. Where can I run it?

List<string> firstList = new List<string>{'fast', 'lunar', 'modern', 'super', 'retro', 'traditional'};
List<string> secondList = new List<string>{'car', 'cat', 'mining', 'office', 'computer', 'ship'};
List<Account> accountsList = new List<account>();

for (String first: firstList){
    for(string second: secondList) {
        Account a = new Account();
        a.Name = first + ' ' + second + ' co';
           accountsList.add(a);
    }
}

insert accountsList;
  • List<string> firstList = new List<string>{'fast', 'lunar', 'modern', 'super', 'retro', 'traditional'}; List<string> secondList = new List<string>{'car', 'cat', 'mining', 'office', 'computer', 'ship'}; List<Account> accountsList = new List<account>(); for (String first: firstList){ for(string second: secondList) { Account a = new Account(); a.Name = first + ' ' + second + ' co'; a.code__c = 'abc'; accountsList.add(a); } } insert accountsList; – user3520799 Mar 5 '16 at 22:44
6

You will use the developer console to insert your apex.

To find the developer console, go to name-> Developer Console:

Enter image description here

Once you are in the developer console, click on menu Debug -> Open Execute Anonymous Windows:

Enter image description here

I see you are new to Apex and coding so get on to the Trailhead and get some training.

https://developer.salesforce.com/trailhead/en/apex_database/apex_database_intro

| improve this answer | |
  • thanks, i was able to insert the records, after correcting the bug in my code. – user3520799 Mar 5 '16 at 22:40
  • @user3520799 mark as answered so that others can find easily – Mohith Shrivastava Mar 5 '16 at 22:44
  • In the screenshot, menu command "Developer Console" appears to be in menu "mohit srivastav", not menu "Setup". What is correct? – Peter Mortensen Mar 6 '16 at 10:02
  • @peter great observation .just corrected!! – Mohith Shrivastava Mar 6 '16 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.