--- sf_webform.module
+++ sf_webform.module
@@ -30,7 +30,7 @@
     'page callback' => 'drupal_get_form',
     'page arguments' => array('sf_webform_associate_webform_node', 4),
     'access arguments' => array('administer salesforce'),
-    'type' => MENU_CALLBACK,
+    'type' => MENU_LOCAL_TASK,
   );
   $items["node/%webform_menu/webform_salesforce"] = array(
     'title' => 'Salesforce Export',
@@ -83,7 +83,7 @@
 
   elseif ($form_id == "salesforce_api_fieldmap_edit_form") {
     $map = salesforce_api_fieldmap_load($form['fieldmap_index']['#value']);
-    if (!empty($map['fields']) && preg_match('/^node_webform_(\d+)$/', $map['drupal'], $matches)) {
+    if (!empty($map->fields) && preg_match('/^node_webform_(\d+)$/', $map->drupal, $matches)) {
       $nid = $matches[1];
       $webform_node = node_load($nid);
       // show the fieldmap and edit link
@@ -95,7 +95,7 @@
         '#collapsed' => FALSE,
       );
       $form['webform_fieldmap']['information'] = array(
-        '#value' => t('This fieldmap is associated with webform node %title (nid %nid) - !link', array("%title" => $webform_node->title, "%nid" => $webform_node->nid, '!link' => l("edit", SALESFORCE_PATH_FIELDMAPS ."/".  $map['fieldmap'] ."/webform", $options = array("query" => "edit=1&destination=". SALESFORCE_PATH_FIELDMAPS ."/". $map['fieldmap'] ."/edit"))))
+        '#value' => t('This fieldmap is associated with webform node %title (nid %nid) - !link', array("%title" => $webform_node->title, "%nid" => $webform_node->nid, '!link' => l("edit", SALESFORCE_PATH_FIELDMAPS ."/".  $map->name ."/webform", $options = array("query" => "edit=1&destination=". SALESFORCE_PATH_FIELDMAPS ."/". $map->name ."/edit"))))
       );
     }
   }
@@ -207,7 +207,7 @@
     // check for user access processing for this webform
     $access = _sf_webform_get_access($node->salesforce, $submission->uid);
 
-    if ($access && $exported && empty($salesforce_submission['sfid'])) {
+    if ($access && $exported && empty($salesforce_submission->sfid)) {
       $submissions[$submission->sid] = '';
       $form['id'][$submission->sid] = array('#value' => $submission->sid);
       $form['date'][$submission->sid] = array('#value' => $date);
@@ -215,8 +215,8 @@
       $form['operation'][$submission->sid] = array('#value' => l("View", "node/". $node->nid ."/submission/". $submission->sid));
     }
     elseif ($access && !$exported) {
-      if (empty($salesforce_submission['sfid']) && $salesforce_submission['sfid'] == 0) $submissions[$submission->sid] = '';
-      if (!$show_all && $salesforce_submission['sfid']) continue;
+      if (empty($salesforce_submission->sfid) && $salesforce_submission->sfid == 0) $submissions[$submission->sid] = '';
+      if (!$show_all && $salesforce_submission->sfid) continue;
       $form['id'][$submission->sid] = array('#value' => $submission->sid);
       $form['date'][$submission->sid] = array('#value' => $date);
       $form['remote_addr'][$submission->sid] = array('#value' => $submission->remote_addr);
@@ -303,7 +303,7 @@
       // check for user access processing for this webform
       $access = _sf_webform_get_access($node->salesforce, $submission->uid);
 
-      if ($access && $exported && empty($salesforce_submission['sfid'])) {
+      if ($access && $exported && empty($salesforce_submission->sfid)) {
         $submissions[$submission->sid] = '';
         $form['webform_node'][$nid]['id'][$submission->sid] = array('#value' => $submission->sid);
         $form['webform_node'][$nid]['date'][$submission->sid] = array('#value' => $date);
@@ -311,8 +311,8 @@
         $form['webform_node'][$nid]['operation'][$submission->sid] = array('#value' => l("View", "node/". $node->nid ."/submission/". $submission->sid));
       }
       elseif ($access && !$exported) {
-        if (empty($salesforce_submission['sfid']) && $salesforce_submission['sfid'] == 0) $submissions[$submission->sid] = '';
-        if ($salesforce_submission['sfid']) continue;
+        if (empty($salesforce_submission->sfid) && $salesforce_submission->sfid == 0) $submissions[$submission->sid] = '';
+        if ($salesforce_submission->sfid) continue;
         $form['webform_node'][$nid]['id'][$submission->sid] = array('#value' => $submission->sid);
         $form['webform_node'][$nid]['date'][$submission->sid] = array('#value' => $date);
         $form['webform_node'][$nid]['remote_addr'][$submission->sid] = array('#value' => $submission->remote_addr);
@@ -488,20 +488,10 @@
  * Redirect form map id when submitted
  */
 function sf_webform_fieldmap_add_form_submit($form, &$form_state) {
-  if (preg_match('/^node_webform_(\d+)$/', $form_state['values']['drupal_object'], $matches)) {
-    // get the fieldmap id from the redirect url
-    $redirect = split("/", $form_state['redirect']);
-    if (!isset($redirect[4]) || !is_numeric($redirect[4])) {
-      drupal_set_message(t('Unable to create association between webform and fieldmap.  Please try again.'), 'error');
-      $form_state['redirect'] = SALESFORCE_PATH_FIELDMAPS;
-    }
-    else {
-      $index = $redirect[4];
-      $nid = $matches[1];
-      _sf_webform_set_webform_index($nid, $index, SALESFORCE_WEBFORM_EXPORT_LOGIN_BOTH);
-      $form_state['redirect'] = SALESFORCE_PATH_FIELDMAPS .'/'. $index .'/webform';
-    }
-
+  if (preg_match('/^node_webform_(\d+)$/', $form_state['values']['drupal'], $matches)) {
+    $map = $form_state['values']['fieldmap'];
+    _sf_webform_set_webform_index($matches[1], $map->fieldmap, SALESFORCE_WEBFORM_EXPORT_LOGIN_BOTH);
+    $form_state['redirect'] = array(SALESFORCE_PATH_FIELDMAPS . '/' . $map->name . '/webform');
   }
 }
 
@@ -526,10 +516,10 @@
 /**
  * Form to relate webform nodes to fieldmaps.
  */
-function sf_webform_associate_webform_node(&$form_state, $index) {
-
-  $fieldmap = _sf_webform_get_webform_fieldmap_info($index);
-  $node = node_load($fieldmap['nid']);
+function sf_webform_associate_webform_node(&$form_state, $name) {
+  $fieldmap =  salesforce_api_fieldmap_load($name);
+  $sf_webform_info = _sf_webform_get_webform_fieldmap_info($fieldmap->fieldmap);
+  $node = node_load($sf_webform_info['nid']);
   $form['webform'] = array(
     '#type' => 'fieldset',
     '#title' => t('Webform: %title', array('%title' => check_plain($node->title))),
@@ -538,25 +528,61 @@
     '#collapsed' => FALSE,
   );
 
-  $form['webform']['fieldmap_index'] = array('#type' => 'hidden', '#value' => $index);
+  $form['webform']['fieldmap'] = array('#type' => 'value', '#value' => $fieldmap);
 
   // Get all webform nodes that are not associated with a node already.
   $form['webform']['webform_nid'] = array(
     '#type' => 'hidden',
     '#title' => t('Webform node'),
-    '#default_value' => isset($fieldmap['nid']) ? $fieldmap['nid'] : 0,
+    '#default_value' => isset($sf_webform_info['nid']) ? $sf_webform_info['nid'] : 0,
     '#description' => t('Select the webform node that this fieldmap should export/import'),
   );
+  
+  $options = array(
+      SALESFORCE_WEBFORM_EXPORT_LOGIN_BOTH => t('Both anonymous & authenticated users'),
+      SALESFORCE_WEBFORM_EXPORT_LOGIN_ANON => t('Anonymous users only'),
+      SALESFORCE_WEBFORM_EXPORT_LOGIN_AUTH => t('Authenticated users only')
+      );
+
+  $default = isset($sf_webform_info['type']) ? $sf_webform_info['type'] : SALESFORCE_WEBFORM_EXPORT_LOGIN_BOTH;
 
+  // TODO: Add support for all existing roles.
+  // We can create at most one fieldmap per role. If a fieldmap already exists
+  // for both anon and auth users, then we cannot create another fieldmap.
+  $existing_fieldmaps = _sf_webform_get_webform_fieldmapid($node->nid);
+  // Of course, we exclude the current fieldmap when considering existing maps.
+  unset($existing_fieldmaps[$sf_webform_info['type']]);
+  
+  if (isset($existing_fieldmaps[SALESFORCE_WEBFORM_EXPORT_LOGIN_BOTH])
+  || count($existing_fieldmaps) > 1) {
+    drupal_set_message(t('Unable to add additional fieldmap for this webform. A fieldmap has already been created for both anonymous and authenticated users. Please edit an existing fieldmap or create a new webform.'), 'error');
+    salesforce_api_fieldmap_delete($fieldmap->name);
+    drupal_goto(SALESFORCE_PATH_FIELDMAPS);
+    exit;
+  }
+  // If a single other fieldmap exists -- regardless of whether it is for auth 
+  // or anon users, then we cannot create a fieldmap for BOTH auth and anon. 
+  // Therefore, unset the option. Further, if $existing_fieldmaps is not empty 
+  // and we made it past the first condition, we know there is exactly one 
+  // existing fieldmap. Therefore, we unset that option and assign the default 
+  // value to remaining option.
+  // TODO: work out how to swap roles between two maps. IE. if map A exists for 
+  // auth and map B for anon, and i want map B to be auth, how do i do it? As 
+  // far as the UI is concerned, a matrix of existing fieldmaps to existing 
+  // roles would probably be the best way forward. Either that or re-think why 
+  // fieldmaps are restricted to one per role.
+  else {
+    if (!empty($existing_fieldmaps)) {
+      unset($options[SALESFORCE_WEBFORM_EXPORT_LOGIN_BOTH]);
+      unset($options[key($existing_fieldmaps)]);
+      $default = key($options);
+    }
+  }
   $form['webform']['login_status'] = array(
     '#type' => 'radios',
     '#title' => t('User login status'),
-    '#default_value' => isset($fieldmap['type']) ? $fieldmap['type'] : SALESFORCE_WEBFORM_EXPORT_LOGIN_BOTH,
-    '#options' => array(
-      SALESFORCE_WEBFORM_EXPORT_LOGIN_BOTH => t('Both anonymous & authenticated users'),
-      SALESFORCE_WEBFORM_EXPORT_LOGIN_ANON => t('Anonymous users only'),
-      SALESFORCE_WEBFORM_EXPORT_LOGIN_AUTH => t('Authenticated users only')
-      ),
+    '#default_value' => $default,
+    '#options' => $options,
     '#description' => t('Select the user login status when this fieldmap should be used.'),
   );
 
@@ -569,57 +595,21 @@
 }
 
 /**
- * Validate webform to fieldmap association
- * only 1 association declared for both login states allowed
- */
-function sf_webform_associate_webform_node_validate($form, &$form_state) {
-
-  $fieldmap = _sf_webform_get_webform_fieldmap_info($form_state['values']['fieldmap_index']);
-
-  $existing_fieldmaps = _sf_webform_get_webform_fieldmapid($form_state['values']['webform_nid']);
-  // Remove the old setting for this fieldmap from the array of existing ones.
-  unset($existing_fieldmaps[$fieldmap['type']]);
-  $existing_types = array_keys($existing_fieldmaps);
-
-  if (!empty($fieldmap)) {
-    // If the type not same as existing.
-    if ($fieldmap['type'] != $form_state['values']['login_status']) {
-
-      // If an existing fieldmap contains ‘both’ do not allow any additional fieldmaps.
-      if (in_array(SALESFORCE_WEBFORM_EXPORT_LOGIN_BOTH, $existing_types)) {
-        form_set_error('login_status', t('A fieldmap has already been created for both anonymous and authenticated users.'), $reset = FALSE);
-      }
-
-      // Do not allow any new fieldmaps with same type.
-      if (in_array($form_state['values']['login_status'], $existing_types)) {
-        form_set_error('login_status', t('This webform is already associated to a fieldmap for this login status'), $reset = FALSE);
-      }
-
-      // If existing types not empty and new type is 'both'.
-      if (!empty($existing_types) && $form_state['values']['login_status'] == SALESFORCE_WEBFORM_EXPORT_LOGIN_BOTH)  {
-        form_set_error('login_status', t('A fieldmap has already been created for both anonymous and authenticated users.'), $reset = FALSE);
-      }
-    }
-  }
-}
-
-/**
  * Create association between webform node and salesforce fieldmap id
  */
 function sf_webform_associate_webform_node_submit($form, &$form_state) {
-
-  $map = salesforce_api_fieldmap_load($form_state['values']['fieldmap_index']);
+  $map = $form_state['values']['fieldmap'];
 
   // If the fieldmap is being edited then delete existing field association.
-  _sf_webform_remove_webform_index($form_state['values']['webform_nid'], $form_state['values']['fieldmap_index']);
+  _sf_webform_remove_webform_index($form_state['values']['webform_nid'], $map->fieldmap);
 
-  $map['fields'] = array();
+  $map->fields = array();
 
   // Save the updated fieldmap.
   //salesforce_api_fieldmap_save($map);
-  _sf_webform_set_webform_index($form_state['values']['webform_nid'], $map['fieldmap'], $form_state['values']['login_status']);
+  _sf_webform_set_webform_index($form_state['values']['webform_nid'], $map->fieldmap, $form_state['values']['login_status']);
 
-  $form_state['redirect'] = SALESFORCE_PATH_FIELDMAPS .'/'. $map['fieldmap'] .'/edit';
+  $form_state['redirect'] = SALESFORCE_PATH_FIELDMAPS .'/'. $map->name .'/edit';
 }
 
 /**
@@ -668,18 +658,17 @@
     // map elements to correct object fields
 
     $submission = webform_get_submission($node->nid, $sid);
-    $fieldmap = _sf_webform_get_fieldmap_id($node->salesforce, $submission);
+    $index = _sf_webform_get_fieldmap_id($node->salesforce, $submission);
   }
   else {
     $sid = $form_state['values']['details']['sid'];
-    $fieldmap = _sf_webform_get_fieldmap_id($node->salesforce);
+    $index = _sf_webform_get_fieldmap_id($node->salesforce);
   }
 
-  // Create an object for export based on the specified fieldmap.
-  $object = salesforce_api_fieldmap_export_create($fieldmap, $node);
+  $map = salesforce_api_fieldmap_load($index);
 
-  // Load the fieldmap so we can get the object name.
-  $map = salesforce_api_fieldmap_load($fieldmap);
+  // Create an object for export based on the specified fieldmap.
+  $object = salesforce_api_fieldmap_export_create($map->name, $node);
 
   if (empty($map))  {
     // Otherwise log the error and return FALSE.
@@ -695,31 +684,30 @@
     // if the form is being submitted directly
     $data = $form_state['values']['submitted'];
 
-    if ($uid_key = array_search(SALESFORCE_WEBFORM_FIELD_UID, $map['fields'])) {
+    if ($uid_key = array_search(SALESFORCE_WEBFORM_FIELD_UID, $map->fields)) {
       // update object to get salesforce key for a particular user
       $object->$uid_key = $user->uid;
     }
 
-    if ($sfid_key = array_search(SALESFORCE_WEBFORM_FIELD_SFID, $map['fields'])) {
+    if ($sfid_key = array_search(SALESFORCE_WEBFORM_FIELD_SFID, $map->fields)) {
       // update object to get salesforce key for a particular user
       $user = user_load(array("uid" => $user->uid));
-      $object->$sfid_key = $user->salesforce['sfid'];
+      $object->$sfid_key = $user->salesforce->sfid;
     }
   }
   else {
 
     // use submission data loaded from webform submission inc
     $data = $submission->data;
-
-    if ($uid_key = array_search(SALESFORCE_WEBFORM_FIELD_UID, $map['fields'])) {
+    if ($uid_key = array_search(SALESFORCE_WEBFORM_FIELD_UID, $map->fields)) {
       // update object to get salesforce key for a particular user
       $object->$uid_key = $submission->uid;
     }
 
-    if ($sfid_key = array_search(SALESFORCE_WEBFORM_FIELD_SFID, $map['fields'])) {
+    if ($sfid_key = array_search(SALESFORCE_WEBFORM_FIELD_SFID, $map->fields)) {
       // update object to get salesforce key for a particular user
       $webform_user = user_load(array("uid" => $submission->uid));
-      $object->$sfid_key = $webform_user->salesforce['sfid'];
+      $object->$sfid_key = $webform_user->salesforce->sfid;
     }
 
   }
@@ -735,7 +723,7 @@
   if (empty($sfid)) {
     // Export the object to Salesforce.
     try {
-      $response = $sf->client->create(array($object), $map['salesforce']);
+      $response = $sf->client->create(array($object), $map->salesforce);
     }
     catch (Exception $e) {
       // Log the error message.
@@ -750,7 +738,7 @@
   }
   else {
     $object->Id = $sfid;
-    $response = $sf->client->update(array($object), $map['salesforce']);
+    $response = $sf->client->update(array($object), $map->salesforce);
   }
 
   // If the export was successful...
@@ -789,36 +777,30 @@
 function _sf_webform_get_fieldmap_id($fieldmap, $submission = NULL) {
   global $user;
 
-  // get all the possible fieldmaps for this webform node
-  $fieldmap_ids = array_keys($fieldmap);
-
   // if there is only one fieldmap id for this node return
-  if (sizeOf($fieldmap_ids) <= 1) {
-    return $fieldmap[current($fieldmap_ids)]['fmid'];
+  if (count($fieldmap) == 1) {
+    $map = current($fieldmap);
+    return $map['fmid'];
   }
-  else {
-    // if multiple fieldmaps exists for auth and anon
-    // webform submissions data, auth user
-    if (!is_null($submission))  {
-      if ($submission->uid != 0)  {
-        return $fieldmap[SALESFORCE_WEBFORM_EXPORT_LOGIN_AUTH]['fmid'];
-      }
-      else{
-        return $fieldmap[SALESFORCE_WEBFORM_EXPORT_LOGIN_ANON]['fmid'];
-      }
+
+  // if multiple fieldmaps exists for auth and anon
+  // webform submissions data, auth user
+  if (!is_null($submission))  {
+    if ($submission->uid != 0)  {
+      return $fieldmap[SALESFORCE_WEBFORM_EXPORT_LOGIN_AUTH]['fmid'];
     }
-    else {
-      // if user is logged in
-      if ($user->uid != 0) {
-        return $fieldmap[SALESFORCE_WEBFORM_EXPORT_LOGIN_AUTH]['fmid'];
-      }
-      else {
-        // if user is not logged in
-        return $fieldmap[SALESFORCE_WEBFORM_EXPORT_LOGIN_ANON]['fmid'];
-      }
+    else{
+      return $fieldmap[SALESFORCE_WEBFORM_EXPORT_LOGIN_ANON]['fmid'];
     }
   }
-  return;
+  // if user is logged in
+  if ($user->uid != 0) {
+    return $fieldmap[SALESFORCE_WEBFORM_EXPORT_LOGIN_AUTH]['fmid'];
+  }
+  else {
+    // if user is not logged in
+    return $fieldmap[SALESFORCE_WEBFORM_EXPORT_LOGIN_ANON]['fmid'];
+  }
 }
 
 /**
@@ -855,6 +837,8 @@
 
 /**
  * Map form post to salesforce object
+ * TODO: This needs to be moved into export/import handler(s)
+ * @see hook_fieldmap_objects() documentation in salesforce/hooks.php
  *
  * @param $data
  *   The node to export.
@@ -866,7 +850,13 @@
  *   object ready for submission to salesforce
  */
 function sf_webform_process_webform($data, $fieldmap, $object) {
-  foreach ($fieldmap['fields'] as $component => $form_key)  {
+  // This is a stop-gap while 1) fieldsToNull doesn't work for enterprise client
+  // and 2) sf_webform doesn't use the typical means of populating the SF object
+  // with import/export handlers in hook_fieldmap_objects()
+  // REMOVE THE NEXT LINE
+  unset($object->fieldsToNull);
+  
+  foreach ($fieldmap->fields as $component => $form_key)  {
     if (strpos($form_key, "webform") !== FALSE && empty($object->$component)) {
       $key = explode("_", $form_key);
 
@@ -1026,7 +1016,7 @@
       $webform_submissions = webform_get_submissions($node->nid);
       foreach ($webform_submissions as $sid => $submission) {
         $salesforce_submission = salesforce_api_id_load('webform', $sid);
-        if ($salesforce_submission['sfid']) continue;
+        if ($salesforce_submission->sfid) continue;
         $success = sf_webform_export($node, NULL, NULL, $sid);
         if ($success) {
           $count++;
