Sharing an account between two devices

In any sales force application, it is a common requirement to share leads, opportunities, and customers with other mobile devices. Without any form of data-sharing capability, the data is locked in your device, and the only way to get it to another device is the unattractive option of rekeying in the data piece by piece.

There are a few ways to send raw data from one device to another. Infrared (IrDA) and Bluetooth are two examples. Before we go into the details of each implementation, let's first decide on a transmission format for your data.

As you know, an account (together with its file attachments, historical records, and tasks) can be conveniently represented using a single dataset object. The easiest way to transmit this account to another device would be to serialize this dataset into a byte array for easy transmission and then to deserialize it back into a dataset at the targeted device.

Let's take a look at the code that you can use to do this:

public static byte[] SerializeDataset(DataSet Data) {

StringWriter strWriter = new StringWriter(); string _result;

ASCIIEncoding _encoding = new ASCIIEncoding(); Data.WriteXml(strWriter);

_result = strWriter.GetStringBuilder()-ToString(); return _encoding.GetBytes(_result);

public static DataSet DeserializeDataset(byte[] Data) {

ASCIIEncoding _encoding = new ASCIIEncoding(); string _stringData;

_stringData = _encoding.GetString(Data, 0, Data.Length); StringReader _reader = new StringReader(_stringData); DataSet _ds = new DataSet(); _ds.ReadXml(_reader); return _ds;

Take note that this Accounts dataset contains only the file attachment metadata and not the actual file attachments themselves. You will need to write additional code to transmit these files one by one to the targeted device as well via Infrared or Bluetooth.

Now that you have decided on a suitable format for data transmission, let's see how you can transmit these byte arrays across Infrared and Bluetooth channels.

Was this article helpful?

0 0

Post a comment