--- salesforcewebform.module	2009-04-21 22:49:16.000000000 -0400
+++ salesforcewebform.module-NEW	2010-05-06 10:28:42.000000000 -0400
@@ -286,19 +286,24 @@ function salesforcewebform_process($form
   // $file_failed =  accounts which failed
   $success = _salesforcewebform_upsert_accounts($client, $sObjects, $file_updated, $file_created, $file_failed);
 
-  // Update the overall counts
-  if (is_array($success))
-  {
-      $accounts_created = $accounts_created + $success[0];
-      $accounts_updated = $accounts_updated + $success[1];
-      $accounts_failed =  $accounts_failed + $success[2];
-  }
-  $total_record_count = $total_record_count + $record_count;
-
-  $form_values['submitted_tree']['webformsid__c'] = $form_values['submitted_tree']['WebformSID__c'];
-  unset($form_values['submitted_tree']['WebformSID__c']);
-  $form_state['values'] = $form_values;
-
+	if (isset($success->faultstring)) {
+		drupal_set_message('Error communicating with SalesForce.com: ' . $success->faultstring . ', Fault code: ' . $success->faultcode, 'error', FALSE);
+	}
+	
+	else {
+		if (is_array($success))
+		{
+				$accounts_created = $accounts_created + $success[0];
+				$accounts_updated = $accounts_updated + $success[1];
+				$accounts_failed =  $accounts_failed + $success[2];
+		}
+		$total_record_count = $total_record_count + $record_count;
+	
+		$form_values['submitted_tree']['webformsid__c'] = $form_values['submitted_tree']['WebformSID__c'];
+		unset($form_values['submitted_tree']['WebformSID__c']);
+		$form_state['values'] = $form_values;
+	}
+	
   return $form_state;
 }
 
@@ -311,42 +316,53 @@ function _salesforcewebform_upsert_accou
     {
         // The upsert process
         $results = $client->upsert("WebformSID__c", $sObjects);
-        $k = 0;
-        // This loop processes $result to build the log files
-        foreach ($results as $result)
-        {
-            // Build string from fields in $sObjects array
-            // At this point, the record has already been upserted
-            // We just need the data for the log file
-            // The string is the same, regardless of the result
-            $data2 = $sObjects[$k]->fields['NAME'] . ", " . $sObjects[$k]->fields['SA_ID__C'];
-
-            if ($result->success)
-            {
-                if ($result->created)
-                {
-                    $accounts_created++;
-                   // file_put_contents($file_created, $data2 . "\n", FILE_APPEND);
-                }
-                else
-                {
-                    $accounts_updated++;
-                   // file_put_contents($file_updated, $data2 . "\n", FILE_APPEND);
-                }
-            }
-            else
-            {
-                $accounts_failed++;
-                // The errors object also contains fields and status_code
-                $errMessage = $result->errors->message;
-               // file_put_contents($file_failed, $data2 . ", " . $errMessage . "\n", FILE_APPEND);
-            }
-            $k++;
-        }
-        // Put the result counts into an array to pass back as the result.
-        $success = array();
-        array_push($success, $accounts_created, $accounts_updated, $accounts_failed);
-        return $success;
+
+
+        // Error handling
+        if (isset($results->errors)) {        	
+        	drupal_set_message('Error communicating with SalesForce.com: ' . $results->errors->message, 'error', FALSE);
+        	return FALSE;
+        } 
+
+				// Sucssess, continue processing
+				else {
+					$k = 0;
+					// This loop processes $result to build the log files
+					foreach ($results as $result)
+					{
+							// Build string from fields in $sObjects array
+							// At this point, the record has already been upserted
+							// We just need the data for the log file
+							// The string is the same, regardless of the result
+							$data2 = $sObjects[$k]->fields['NAME'] . ", " . $sObjects[$k]->fields['SA_ID__C'];
+	
+							if ($result->success)
+							{
+									if ($result->created)
+									{
+											$accounts_created++;
+										 // file_put_contents($file_created, $data2 . "\n", FILE_APPEND);
+									}
+									else
+									{
+											$accounts_updated++;
+										 // file_put_contents($file_updated, $data2 . "\n", FILE_APPEND);
+									}
+							}
+							else
+							{
+									$accounts_failed++;
+									// The errors object also contains fields and status_code
+									$errMessage = $result->errors->message;
+								 // file_put_contents($file_failed, $data2 . ", " . $errMessage . "\n", FILE_APPEND);
+							}
+							$k++;
+					}
+					// Put the result counts into an array to pass back as the result.
+					$success = array();
+					array_push($success, $accounts_created, $accounts_updated, $accounts_failed);
+					return $success;
+				}
     }
     catch (exception $e)
     {
