Salesforce.com interface to directly access Salesforce.com

Dependencies:   HTTPClient-SSL MbedJSONValue

Dependents:   df-2014-salesforce-hrm-k64f

Fork of SalesforceInterface by Doug Anson

Revision:
18:7dc9b949bbc3
Parent:
17:6c774354b599
Child:
19:6a791e5449b3
--- a/SalesforceInterface.cpp	Tue Sep 23 22:01:43 2014 +0000
+++ b/SalesforceInterface.cpp	Wed Sep 24 04:13:17 2014 +0000
@@ -55,6 +55,7 @@
      this->m_http_status = HTTP_OK;
      this->m_http_response_code = -1;
      RESET_BUFFER(this->m_http_redirection_url);
+     RESET_SML_BUFFER(this->m_error_buffer);
      memset(this->m_salesforce_api,0,SALESFORCE_API_VERSION_LENGTH);
      strcpy(this->m_salesforce_api,SALESFORCE_API_VERSION);
      this->resetSalesforceToken();
@@ -311,12 +312,27 @@
 
  // UPDATE: a specific record in Salesforce.com
  bool SalesforceInterface::updateRecord(char *object_name,char *record_id,MbedJSONValue &record) {
-    return this->updateRecord(object_name,record_id,(char *)record.serialize().c_str());
+    RESET_SML_BUFFER(this->m_error_buffer);
+    return this->updateRecord(object_name,record_id,(char *)record.serialize().c_str(),this->m_error_buffer,MAX_SMALL_BUFFER_LENGTH);
  }
  
  // UPSERT: update/insert an External ID record in Salesforce.com
  bool SalesforceInterface::upsertRecord(char *object_name,char *external_id_field_name,char *external_id_field_value,MbedJSONValue &record) {
-     return this->upsertRecord(object_name,external_id_field_name,external_id_field_value,(char *)record.serialize().c_str());
+     RESET_SML_BUFFER(this->m_error_buffer);
+     return this->upsertRecord(object_name,external_id_field_name,external_id_field_value,(char *)record.serialize().c_str(),this->m_error_buffer,MAX_SMALL_BUFFER_LENGTH);
+ }
+ 
+ // DELETE: a specific record in Salesforce.com
+ bool SalesforceInterface::deleteRecord(char *object_name,char *record_id) {
+      RESET_SML_BUFFER(this->m_error_buffer);
+      return this->deleteRecord(object_name,record_id,this->m_error_buffer,MAX_SMALL_BUFFER_LENGTH);
+ }
+ 
+ // ERROR: get last error result
+ MbedJSONValue SalesforceInterface::getLastError() {
+     MbedJSONValue error;
+     if (strlen(this->m_error_buffer) > 0) parse(error,this->m_error_buffer);
+     return error;
  }
  
  // CREATE: a record in Salesforce.com
@@ -402,7 +418,7 @@
  }
 
  // UPDATE: a specific record in Salesforce.com
- bool SalesforceInterface::updateRecord(char *object_name,char *record_id,char *json_data) {  
+ bool SalesforceInterface::updateRecord(char *object_name,char *record_id,char *json_data,char *output_buffer,int output_buffer_length) {  
      // 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
@@ -428,8 +444,7 @@
                 DEBUG("updateRecord: URL: %s DATA: %s",str_url.c_str(),json_data);
                 
                 // now invoke with POST with JSON data type
-                ALLOC_SML_BUFFER(output_buffer);
-                char *reply = this->invoke(str_url.c_str(),json_data,strlen(json_data)+1,output_buffer,MAX_SMALL_BUFFER_LENGTH);
+                char *reply = this->invoke(str_url.c_str(),json_data,strlen(json_data)+1,output_buffer,output_buffer_length);
                 
                 // DEBUG
                 DEBUG("updateRecord: http status=%d",this->httpResponseCode());
@@ -453,7 +468,7 @@
  }
  
  // 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) {  
+ 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) {  
      // 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
@@ -485,8 +500,7 @@
                 DEBUG("upsertRecord: URL: %s DATA: %s",str_url.c_str(),json_data);
                 
                 // now invoke with POST with JSON data type
-                ALLOC_SML_BUFFER(output_buffer);
-                char *reply = this->invoke(str_url.c_str(),json_data,strlen(json_data)+1,output_buffer,MAX_SMALL_BUFFER_LENGTH);
+                char *reply = this->invoke(str_url.c_str(),json_data,strlen(json_data)+1,output_buffer,output_buffer_length);
                 
                 // DEBUG
                 DEBUG("upsertRecord: http status=%d",this->httpResponseCode());
@@ -510,7 +524,7 @@
  }
   
  // DELETE: a specific record in Salesforce.com
- bool SalesforceInterface::deleteRecord(char *object_name,char *record_id) {
+ bool SalesforceInterface::deleteRecord(char *object_name,char *record_id,char *output_buffer,int output_buffer_length) {
      // 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
@@ -534,7 +548,7 @@
                 
                 // now invoke with DELETE 
                 ALLOC_SML_BUFFER(output_buffer);
-                char *reply = this->invoke(str_url.c_str(),output_buffer,MAX_SMALL_BUFFER_LENGTH,DELETE);
+                char *reply = this->invoke(str_url.c_str(),output_buffer,output_buffer_length,DELETE);
                 
                 // DEBUG
                 DEBUG("deleteRecord: http status=%d",this->httpResponseCode());