diff --git a/apachesolr.install b/apachesolr.install
index a54a359..ed66ec6 100644
--- a/apachesolr.install
+++ b/apachesolr.install
@@ -123,6 +123,7 @@ function apachesolr_schema() {
         'minimum_version' => 1,
         'current_version' => 1,
       ),
+      'subrecords callback' => 'apachesolr_ctools_environment_load_index_bundles',
     ),
     'fields' => array(
       'env_id' => array(
diff --git a/apachesolr.module b/apachesolr.module
index b4e6983..2fac5cd 100644
--- a/apachesolr.module
+++ b/apachesolr.module
@@ -1710,6 +1710,14 @@ function apachesolr_get_index_bundles($env_id, $entity_type) {
       ':env_id' => $env_id,
       ':entity_type' => $entity_type,
       ))->fetchCol();
+
+    if ($environment = apachesolr_environment_load($env_id)) {
+      // If environment is code only return it's index bundles directly from the
+      // object properties.
+      if (!empty($environment->in_code_only) && !empty($environment->index_bundles)) {
+        return $environment->index_bundles;
+      }
+    }
   }
   return array();
 }
@@ -2429,6 +2437,20 @@ function theme_apachesolr_settings_title($vars) {
 }
 
 /**
+ * Export callback to load the view subrecords, which are the index bundles.
+ */
+function apachesolr_ctools_environment_load_index_bundles(&$environments) {
+  foreach($environments as &$environment) {
+    $environment->index_bundles = array();
+    foreach (entity_get_info() as $type => $info) {
+      if ($bundles = apachesolr_get_index_bundles($environment->env_id, $type)) {
+        $environment->index_bundles[$type] = $bundles;
+      }
+    }
+  }
+}
+
+/**
  * Callback for saving Apache Solr environment CTools exportables.
  *
  * CTools uses objects, while Apache Solr uses arrays; turn CTools value into an
@@ -2438,6 +2460,11 @@ function theme_apachesolr_settings_title($vars) {
  *   An environment object.
  */
 function apachesolr_ctools_environment_save($environment) {
+  if (!empty($environment->index_bundles)) {
+    foreach ($environment->index_bundles as $type => $bundles) {
+      apachesolr_index_set_bundles($environment->env_id, $type, $bundles);
+    }
+  }
   apachesolr_environment_save((array) $environment);
 }
 
@@ -2471,7 +2498,15 @@ function apachesolr_ctools_environment_export($environment, $indent) {
   // Re-load the enviroment, since in some cases the conf
   // is stripped since it's not in the actual schema.
   $environment = (object) apachesolr_environment_load($environment->env_id);
+
+  $index_bundles = array();
+  foreach (entity_get_info() as $type => $info) {
+    if ($bundles = apachesolr_get_index_bundles($environment->env_id, $type)) {
+      $index_bundles[$type] = $bundles;
+    }
+  }
+
   $additions_top = array();
-  $additions_bottom = array('conf' => $environment->conf);
+  $additions_bottom = array('conf' => $environment->conf, 'index_bundles' => $index_bundles);
   return ctools_export_object('apachesolr_environment', $environment, $indent, NULL, $additions_top, $additions_bottom);
 }
