Salesforce.com interface to directly access Salesforce.com

Dependencies:   HTTPClient-SSL MbedJSONValue

Dependents:   df-2014-salesforce-hrm-k64f

Fork of SalesforceInterface by Doug Anson

Files at this revision

API Documentation at this revision

Comitter:
ansond
Date:
Thu Sep 25 05:35:05 2014 +0000
Parent:
19:6a791e5449b3
Child:
21:e5a4471a46fb
Commit message:
additional handling of error messages that come back in error conditions

Changed in this revision

SalesforceInterface.cpp Show annotated file Show diff for this revision Revisions of this file
SalesforceInterface.h Show annotated file Show diff for this revision Revisions of this file
--- a/SalesforceInterface.cpp	Thu Sep 25 03:37:57 2014 +0000
+++ b/SalesforceInterface.cpp	Thu Sep 25 05:35:05 2014 +0000
@@ -418,7 +418,10 @@
  }
 
  // UPDATE: a specific record in Salesforce.com
- bool SalesforceInterface::updateRecord(char *object_name,char *record_id,char *json_data,char *output_buffer,int output_buffer_length) {  
+ bool SalesforceInterface::updateRecord(char *object_name,char *record_id,char *json_data,char *output_buffer,int output_buffer_length) { 
+     // reset the error buffer
+     RESET_SML_BUFFER(this->m_error_buffer);
+      
      // parameter check
      if (object_name != NULL && strlen(object_name) > 0 && json_data != NULL && strlen(json_data) > 0) {
          // first we have to ensure that we have valid salesforce token
@@ -451,6 +454,9 @@
                 
                 // return our status
                 if (this->httpResponseCodeInRange(200)) return true;
+                
+                // we are in error - so copy the result if we have one and return false
+                if (reply != NULL && strlen(reply) > 0) strncpy(this->m_error_buffer,reply,this->min(strlen(reply),MAX_SMALL_BUFFER_LENGTH));
                 return false;
             }
          }
@@ -469,6 +475,9 @@
  
  // UPSERT: update/insert a specific External record in Salesforce.com
  bool SalesforceInterface::upsertRecord(char *object_name,char *external_id_field_name,char *external_id_field_value,char *json_data,char *output_buffer,int output_buffer_length) {  
+     // reset the error buffer
+     RESET_SML_BUFFER(this->m_error_buffer);
+
      // parameter check
      if (object_name != NULL && strlen(object_name) > 0 && json_data != NULL && strlen(json_data) > 0) {
          // first we have to ensure that we have valid salesforce token
@@ -507,6 +516,9 @@
                 
                 // return our status
                 if (this->httpResponseCodeInRange(200)) return true;
+                
+                // we are in error - so copy the result if we have one and return false
+                if (reply != NULL && strlen(reply) > 0) strncpy(this->m_error_buffer,reply,this->min(strlen(reply),MAX_SMALL_BUFFER_LENGTH));
                 return false;
             }
          }
@@ -525,6 +537,9 @@
   
  // DELETE: a specific record in Salesforce.com
  bool SalesforceInterface::deleteRecord(char *object_name,char *record_id,char *output_buffer,int output_buffer_length) {
+     // reset the error buffer
+     RESET_SML_BUFFER(this->m_error_buffer);
+
      // parameter check
      if (object_name != NULL && strlen(object_name) > 0 && record_id != NULL && strlen(record_id) > 0) {
          // first we have to ensure that we have valid salesforce token
@@ -555,6 +570,9 @@
                 
                 // return our status
                 if (this->httpResponseCodeInRange(200)) return true;
+                
+                // we are in error - so copy the result if we have one and return false
+                if (reply != NULL && strlen(reply) > 0) strncpy(this->m_error_buffer,reply,this->min(strlen(reply),MAX_SMALL_BUFFER_LENGTH));
                 return false;
             }
          }
@@ -800,4 +818,10 @@
      int diff = http_response - n;
      if (diff >= 0 && diff < 100) return true;
      return false;
+ }
+ 
+ // min() method
+ int SalesforceInterface::min(int value1,int value2) {
+     if (value1 < value2) return value1;
+     return value2;
  }
\ No newline at end of file
--- a/SalesforceInterface.h	Thu Sep 25 03:37:57 2014 +0000
+++ b/SalesforceInterface.h	Thu Sep 25 05:35:05 2014 +0000
@@ -635,6 +635,9 @@
         
         // validate that http status is in the "n" range
         bool httpResponseCodeInRange(int n);
+        
+        // min() method
+        int min(int value1,int value2);
  };
  
  #endif // _SALESFORCE_INTERFACE_H_
\ No newline at end of file