Answers.Body: <p>On the main <code>MyPluginPlugin</code> class, there is a method you can override called <code>onAfterInstall()</code>. Which will run after your plugin is installed.</p>
  
  <p>To create those records, you can place the following code into the method:</p>
  
  <pre><code>public function onAfterInstall()
  {
      $record = new MyPlugin_ExampleRecord;
      $record-&gt;setAttribute('attributeName', 'value');
      $record-&gt;save();
  
      $record2 = new MyPlugin_ExampleRecord;
      $record2-&gt;setAttribute('attributeName', 'value2');
      $record2-&gt;save();
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-09T18:12:08.470Z
Answers.LastActivityDate: 2016-08-09T18:12:08.470Z
Answers.UserDisplayName: Jason McCallister
Body: <p>When I install the plugin, I need to automatically create a few records. How can I have my plugin automatically create those records when it is installed?</p>
  
Tags: <plugin-development><records><installation>
Title: How can I populate some records after my plugin is installed?
ThreadText: # How can I populate some records after my plugin is installed?
  
  (Asked by: username_0 on 2016-08-09)
  
  When I install the plugin, I need to automatically create a few records. How can I have my plugin automatically create those records when it is installed?
  
  **Tags:** plugin-development, records, installation
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2016-08-09. Score: 5
  
  On the main `MyPluginPlugin` class, there is a method you can override called `onAfterInstall()`. Which will run after your plugin is installed.
  
  To create those records, you can place the following code into the method:
  
  ```
  public function onAfterInstall()
  {
      $record = new MyPlugin_ExampleRecord;
      $record->setAttribute('attributeName', 'value');
      $record->save();
  
      $record2 = new MyPlugin_ExampleRecord;
      $record2->setAttribute('attributeName', 'value2');
      $record2->save();
  }
  
  ```
  
  
  ---
  
  