Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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;
share|improve this question
    
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 at 22:44
up vote 6 down vote accepted

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

share|improve this answer
    
thanks, i was able to insert the records, after correcting the bug in my code. – user3520799 Mar 5 at 22:40
    
@user3520799 mark as answered so that others can find easily – Mohith Shrivastava Mar 5 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 at 10:02
    
@peter great observation .just corrected!! – Mohith Shrivastava Mar 6 at 10:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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