Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Section


Panel
titleData Sync


Panel
titlesyncinfo


Info

The syncinfo query returns the following information about the last Pulsar sync:

  • Last Sync Attempt Date/Time
  • Last Successful Sync Date/Time


Code Block
languagejs
var request = { 
	"type" : "syncinfo",
	"data" : { } // empty object- this is required in the current API
};

bridge.sendRequest(request, function (results) {
	console.log('Javascript got its response: ' + results);
    if (results.type === "syncinfoResponse")	{
		var lastsyncattempt = results.data.lastsyncattempt;
        var lastsuccessfulsync = results.data.lastsuccessfulsync;
    } else if (results.type == 'error') {
	    errStr = results.data;
	    alert('A problem occurred:\n' + errStr);
    }
});    



Panel
titlesyncdata


Note
iconfalse

The syncdata request will attempt to initiate a Pulsar sync action. This method is equivalent to pressing the "Sync now" button from the native Pulsar home screen.

A standard sync is run by default without specifying any parameters.  To initiate a non-standard sync, you can specify additional parameters within the data node:

  • singleObjectSyncEnabled: Set to true to run a single object sync. This syncs a single (or root) object at minimum, but by default will retrieve all objects at one level above (parents) and one level below (children) the root object.
    • rootObjectId (required): The Id of the specific record you'd like to sync.
    • parentIdFieldList (optional): A list of reference type field names on the root object to also sync. If not specified, all objects referenced in all reference fields will be synced (for those object types already being synced). To disable this, you may specify a single invalid field (e.g. ["NONE"]).
    • childRelationshipList (optional): A list of child relationships on the root object to also sync. If not specified, all child relationships are utilized to sync objects at this level (for those object types already being synced). To disable this, you may specify a single invalid child relationship (e.g. ["NONE"]).
  • pushChangesSyncEnabled: Set to true to run a push changes sync. This skips directly to the sync stage that pushes all local changes to Salesforce.
  • useCompositeGraph: Set to true to explicitly use the Composite Graph API. Currently, this applies only to push changes sync.


NOTE: For older Pulsar versions, the 'syncData' API request will register and de-register for sync notifications automatically, restricting sync notification responses to API-initiated syncs. With the release of versions 2.1.6 (Android and UWP) and 3.1.0 (iOS), 'syncData' will maintain its current behavior, but now sync notification handlers can also be managed separately, using the 'registerSync' API method (see below).


Code Block
languagejs
var request = { 
	"type" : "syncdata",
	"data" : { } // empty object- this is required in the current API
};

bridge.sendRequest(request, function (results) {
	console.log('Javascript got its response: ' + results);
	if (results.type === "syncDataResponse")	{
		// successfully requested sync
	} else if (results.type == 'error') {
		 errStr = results.data;
		 alert('A problem occurred:\n' + errStr);
	}
});

An example of a Composite Graph API enabled push changes sync:

Code Block
languagejs
var request = { 
	"type" : "syncdata",
	"data" : {
		"pushChangesSyncEnabled" : true, 
		"useCompositeGraph" : true
	}
};

An example of a single object sync that syncs the root object and all parent and child objects:

Code Block
languagejs
var request = { 
	"type" : "syncdata",
	"data" : {
		"singleObjectSyncEnabled" : true, 
		"rootObjectId" : "001234567890123AAA"
	}
};

An example of a single object sync that syncs the root object (Contact) and a subset of parent and child objects:

Code Block
languagejs
var request = { 
	"type" : "syncdata",
	"data" : {
		"singleObjectSyncEnabled" : true, 
		"rootObjectId" : "003d0000032lc1ZAAQ",
		"parentIdFieldList" : ["AccountId","ReportsToId"],
		"childRelationshipList" : ["Cases","Events","Notes","Tasks"]
	}
};

An example of a single object sync that syncs the root object only:

Code Block
languagejs
var request = { 
	"type" : "syncdata",
	"data" : {
		"singleObjectSyncEnabled" : true, 
		"rootObjectId" : "001234567890123AAA",
		"parentIdFieldList" : "NONE",
		"childRelationshipList" : "NONE"
	}
};



Panel
titleHandling Sync Notifications


Info
titleOverview

The Pulsar sync process provides a feedback mechanism for monitoring the overall progress of the sync.

WARNING: Once you have requested a sync, you should not perform any create/update/delete calls until sync has finished.

WARNING: Be aware of your context. If your document is running inside PulsarSFS, you should avoid using the add/remove handler functions on the bridge in favor of some methods that reside on the Pulsar SFS window object. Learn more about the Pulsar SFS window object: Pulsar SFS UI Customizations#Pulsar-FSL-Functions.

You can hook into progress and completion notifications from javascript by registering handler functions with the Pulsar bridge. There can only be one handler assigned to a given handler name. See the examples of handler setup below:


Code Block
languagejs
......
// during bridge initialization
bridge.addHandler = function(handlerName, handler) {
	window.WebViewJavascriptBridge.registerHandler(handlerName, handler);
};
bridge.removeHandler = function(handlerName) {
    window.WebViewJavascriptBridge.deregisterHandler(handlerName);
};
......

// Add a handler
bridge.addHandler("handlerA", function(data) { console.log("handlerA called from Pulsar"); });

doSomethingThatMakesPulsarCallHandlerA();

// Remove a handler
bridge.removeHandler("handlerA");


// If running in Pulsar SFS //

// ... get the Pulsar window object explained above

pulsar.addSyncUpdateHandler('myUpdateHandler', function(updateInfo) {
	console.log('Sync has updated with info: ', updateInfo);
});

pulsar.addSyncFinishedHandler('myHandlerName', function(syncFinishedInfo) {
	console.log('Sync has finished with info: ', syncFinishedInfo);

	// please remove your handlers!
	pulsar.removeSyncFinishedHandler('myHandlerName');
	pulsar.removeSyncUpdateHandler('myUpdateHandler');
});



Panel
titleSync Progress


Info
titlesyncDataUpdate handler

To receive progress updates during a sync initiated with the syncData request, register a handler with the name "syncDataUpdate". This function will receive an object with the progress information:

  1. "syncpass" - The Pulsar sync may take one or more passes to fully complete. This will be delivered as a string containing the pass number, an integer value
  2. "syncpercent" - This value will be delivered as a string containing a floating point value between 0 and 100.00. This value is relative to the current sync pass, so may reach 100.00 more than once.


Code Block
languagejs
// Add a handler to respond to sync progress updates
bridge.addHandler("syncDataUpdate", function(dataObj) {
    if (dataObj.hasOwnProperty("syncpercent") && dataObj.hasOwnProperty("syncpass")) {
        var syncPass = dataObj.syncpass;
		var syncPercent = dataObj.syncpercent;
		someScreenUpdate(syncPass, syncPercent);
		....
    }
});



Panel
titleSync Completion


Info
titlesyncDataFinished handler

To receive completion notifications for a sync initiated with the syncData request, register a handler with the name  "syncDataFinished". This function will receive an object with the completion success status.


Code Block
languagejs
// Add a handler to respond to sync finished event
bridge.addHandler("syncDataFinished", function(dataObj) {
    console.log("sync data finished");
    if (dataObj.hasOwnProperty("success")) {
        if (dataObj.success) {
            doSyncSuccess();
        } else {
            doSyncFailure();
        }
    }
});



Panel
titleRegister for Notifications


Info
titleregisterSync

Once either or both of the sync progress and completion handlers have been registered with the Pulsar bridge, the 'registerSync' request can be used to enable these handlers to respond to any sync events that occur, not just API initiated ones. This request takes a single boolean parameter to determine whether we are registering ("true") or de-registering ("false") for sync notifications.


NOTE: this is new functionality for Pulsar versions 2.1.6 (Android and UWP) and 3.1.0 (iOS) – in older releases the 'syncData' API request will register and de-register for sync notifications automatically, restricting this behavior to API-initiated syncs.


Code Block
languagejs
var request = { 
	"type" : "registerSync",
	"data" : "TRUE" // required- this is the value to set "FALSE" for de-registering, "TRUE" for registering
};

bridge.sendRequest(request, function (results) {
	if (results.type === "registersyncResponse")	{
		var registeredForSync = results.data.registered; //string value "TRUE" or "FALSE"
		// do something with the information
    } else if (results.type == 'error') {
	    errStr = results.data;
	    alert('A problem occurred:\n' + errStr);
    }
});  




Panel
titleinterruptsync


Info

The interruptsync request will attempt to stop the currently running sync, if any.


Code Block
var request = { 
	"type" : "interruptsync",
	"data" : { } // empty object- this is required in the current API
};
bridge.sendRequest(request, function(responseData) {
    if (responseData.type === "interruptSyncResponse") {
        console.log('interruptSync: ' + responseData.data);
        var syncSuccess = responseData.data.success;
    } else if (responseData.type == 'error') {
        var errStr = responseData.data;
        console.log('A problem occurred:\n' + errStr);
    }
});




Panel
titleAuto-Sync Status


Panel
titlegetAutosyncStatus


Info

The getAutosyncStatus operation will return Pulsar's current auto-sync status. This is the functionality that controls whether a sync starts automatically on login and when you return to the app. This will return the string "FALSE" if this functionality is off, and "TRUE" if this functionality is turned on.


Code Block
var request = { 
	"type" : "getAutosyncStatus",
	"data" : { } // empty object- this is required in the current API
};

bridge.sendRequest(request, function (results) {
	console.log('Javascript got its response: ' + results);
    if (results.type === "getAutosyncStatusResponse")	{
		var isAutoSyncOn = results.data; //string value "TRUE" or "FALSE"
		// do something with the information
    } else if (results.type == 'error') {
	    errStr = results.data;
	    alert('A problem occurred:\n' + errStr);
    }
});    



Panel
titlesetAutosyncStatus


Info

The setAutosyncStatus operation will attempt to set Pulsar's current auto-sync status. Similar to getAutosyncStatus, this will return the string "FALSE" if this functionality is off after attempting to set it, and "TRUE" if this functionality is turned on after the attempt.


Code Block
var request = { 
	"type" : "setAutosyncStatus",
	"data" : "TRUE" // required- this is the value to set "FALSE" for off, "TRUE" for on
};

bridge.sendRequest(request, function (results) {
	console.log('Javascript got its response: ' + results);
    if (results.type === "setAutosyncStatusResponse")	{
		var isAutoSyncOn = results.data; //string value "TRUE" or "FALSE"
		// do something with the information
    } else if (results.type == 'error') {
	    errStr = results.data;
	    alert('A problem occurred:\n' + errStr);
    }
});    




...