Ensure Data Integrity Between SFDC and an Mobile Client Device

What are the best practices to ensure SFDC REST API communications are transmitted to and from a mobile device with full integrity?

I have a custom iOS app that allows offline editing of Force.com data by field sales reps accessing via 3G-enabled iPads. Everything works well in testing, but field users often complain of sync issues. We can’t replicate these issues and think that they are being caused by some sort of data corruption in the communication between the app and SFDC. Maybe the user drives through a tunnel or does something else to momentarily loose their mobile data connection. To safeguard against this, I would like to implement some sort of technique (compression, checksum, ???) which will help ensure that the data have been transmitted without any loss.

Are there any best practices to help ensure integrity between a client and SFDC?


The Internet is based on a protocol suite known as TCP/IP. The Transmission Control Protocol (TCP) is responsible for ensuring that the data is not corrupted and was received in its entirety, in the proper order, through a series of checksums, serial numbers, and acks/nacks that prevent casual corruption due to poor network connectivity, latency, or “flipped bits.” Furthermore, most network stacks automatically enable compression for HTTP TCP-based connections as a matter of efficiency on the network. The physical link layer (PHY layer in OSI) also verifies data sends from the next repeating point (e.g. router).

Given that the Internet is essentially impervious to randomly corrupted bits, I would suggest that the problem lies elsewhere. A more probable cause would be a failure to correct catch network errors at the application level rather than any other level in the stack. Generally, this means catching whatever exceptions are thrown and taking appropriate action depending on the error presented through the application programming interface. A pre-maturely severed connection would indicate that the application needs to attempt a retry, for example.

Many novice programmers fail to program defensively against errors, which leads to subtle bugs that may appear in particular circumstances. The best defense against these errors is properly catching, handling, and reporting these errors as they occur, as appropriate. I remember many years ago in my programming class, they first taught us how to read errors, and how to handle errors in code, while later, my programming classes talked only about how to “write” code, and would rarely mention “how to handle errors”, even though exceptions are a daily part of a program’s lifecycle.

An exception doesn’t mean the programmer has done something wrong, it means that “something unusual” has occurred. As such, programmers must handle them correctly because “something unusual” will occur more frequently than not, and the program must be well-equipped to handle that situation so that they can be resolved. Not handling exceptions will lead to data corruption and data loss, and possibly crashes.

Note that none of this is specific to salesforce.com, but more formally generic programming advice. I would state that you can, and should, find a good test suite for whichever language you’re using (such as cucumber or JUnit), and write proper tests that include possible failure conditions. By writing unit tests, you can verify that your program will operate correctly in the field.

Source : Link , Question Author : Cameron , Answer Author : sfdcfox

Leave a Comment