As far as I'm aware the only time the publisher.post
event is fired is when the Submit button is clicked within a Salesforce1 custom publisher action.
There is currently no way to subscribe to sforce.one
methods as they don't fire the publisher
events, nor do they offer the facility to provide a callback method.
An alternative is to use Visualforce Remote Objects, AJAX Toolkit or JavaScript Remoting. All of which allow you to define callback functions.
Here are some examples (taken from the documentation linked above):
Visualforce Remote Objects
var ctDetails = { FirstName: 'Marc', LastName: 'Benioff' };
var ct = new RemoteObjectModel.Contact();
ct.create(ctDetails, function(err) {
if(err) {
console.log(err);
alert(err.message);
}
else {
// this is the contact
console.log(ct.log()); // Dump contact to log
console.log(ct.get('Id')); // Id is set when create completes
}
});
AJAX Toolkit
var account = new sforce.SObject("Account");
account.Name = "my new account";
sforce.connection.create([account], {onSuccess : success, onFailure : failed});
function success(result) {
if (result[0].getBoolean("success")) {
log("new account created with id " + result[0].id);
} else {
log("failed to create account " + result[0]);
}
}
function failed(error) {
log("An error has occurred " + error);
}
JavaScript Remoting
var accountName = document.getElementById('acctSearch').value;
Visualforce.remoting.Manager.invokeAction(
'{!$RemoteAction.MyController.getAccount}',
accountName,
function(result, event){
if (event.status) {
document.getElementById('acctId').innerHTML = result.Id
document.getElementById('acctName').innerHTML = result.Name;
} else if (event.type === 'exception') {
document.getElementById("responseErrors").innerHTML =
event.message + "<br/>\n<pre>" + event.where + "</pre>";
} else {
document.getElementById("responseErrors").innerHTML = event.message;
}
}
);