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:
Wed Sep 24 04:13:17 2014 +0000
Parent:
17:6c774354b599
Child:
19:6a791e5449b3
Commit message:
updates for hrm

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	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());
--- a/SalesforceInterface.h	Tue Sep 23 22:01:43 2014 +0000
+++ b/SalesforceInterface.h	Wed Sep 24 04:13:17 2014 +0000
@@ -462,6 +462,7 @@
         char             m_http_redirection_url[MAX_BUFFER_LENGTH+1];
         char             m_salesforce_id[MAX_BUFFER_LENGTH+1];
         char             m_salesforce_api[SALESFORCE_API_VERSION_LENGTH];
+        char             m_error_buffer[MAX_SMALL_BUFFER_LENGTH+1];
         
     public:
         /**
@@ -574,6 +575,12 @@
         */
         // HTTP Error code access
         int httpResponseCode();
+        
+        /**
+        Retrieve the last executed update, upsert, or delete response error detail
+        @return http response code from last update, upsert, or delete operation
+        */
+        MbedJSONValue getLastError();
                       
  protected: 
         // do we have a valid salesforce token and OAUTH token?
@@ -586,11 +593,14 @@
         char *readRecord(char *object_name,char *record_id,char *record_value,char *output_buffer,int output_buffer_length);
         
         // UPDATE: a specific record in Salesforce.com
-        bool updateRecord(char *object_name,char *record_id,char *json_data);
+        bool updateRecord(char *object_name,char *record_id,char *json_data,char *output_buffer,int output_buffer_length);
         
         // UPSERT: update/insert a specific External record in Salesforce.com
-        bool upsertRecord(char *object_name,char *external_id_field_name,char *external_id_field_value,char *json_data);
+        bool upsertRecord(char *object_name,char *external_id_field_name,char *external_id_field_value,char *json_data,char *output_buffer,int output_buffer_length);
                             
+        // DELETE: delete a specific record in Salesforce.com
+        bool deleteRecord(char *object_name,char *record_id,char *output_buffer,int output_buffer_length);
+        
         // raw invocation of REST calls into Salesforce.com
         char *invoke(const char *url,char *output_buffer,int output_buffer_length);                                                                                                        // defaults to GET
         char *invoke(const char *url,char *output_buffer,int output_buffer_length,HttpVerb verb);                                                                                          // GET or DELETE with simple output