3

I'm writing a visualforce page as a custom object action for Salesforce1 app accessed on user's mobile devices (e.g. iPhone) and need to refresh the detail screen when the user clicks the Cancel button.

enter image description here

I can do this easily when the user clicks the Submit button (code shown below) but I can't figure out how to force the publisher to refresh when the user clicks the Cancel button.

Normally, if the user clicks the Submit button then I can simply subscribe to the publisher.post event and fire a publisher.close like this:

Sfdc.canvas.publisher.subscribe({name: "publisher.post", onData:function(e) {
  // do something ...
  Sfdc.canvas.publisher.publish({name: "publisher.close", payload:{ refresh:"true"}});
});

I read the Salesforce1 cheatsheet and it mentions there is a publisher.clearPanelState event. I subscribed to this event but I can't figure out how to force the publisher to refresh the data so the user's device has the latest information rather than the stale cached copy.

Sfdc.canvas.publisher.subscribe({name: "publisher.clearPanelState", onData:function(e) {
    // when user clicks 'Cancel' button this is logged and I see it
    console.log('publisher.clearPanelState');
    // but neither this causes a refresh
    Sfdc.canvas.publisher.publish({name: "publisher.close", payload:{ refresh:"true"}});
    // nor this line causes a refresh
    Sfdc.canvas.publisher.publish({name: "publisher.refresh", payload:{ refresh:"true"}});
}});

The use case is that a record may have a "status" field and this action should only be used when "status=X". The record in the Salesforce database is "status=Y" but since the data may be cached on the user's device they may still see "status=X". When the user tries to use my publisher action I detect this scenario and inform the user they can't take action. I can tell them they need to refresh their data (click cancel button then pull to refresh, etc..) but it would be awesome if I could automate the refresh when the user clicks the Cancel button.

Thanks!

  • do you have solution for this problem? in our case, we need to update the related list as we are adding child record in custom action. – kshitij Feb 11 '16 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.