+ Start a Discussion
jgaiottojgaiotto 

Service cloud console tab / subtab closing & javascript remoting

Hi everyone,

 

I have an inline VFPage in which I detect page closing or page refresh or whenever the user leaves the page using the <body onunload="jsFunction()">. When it happens, I call some Apex code using Javascript remote action.

 

It works perfectly in the "standard" view of a page. But when I am using the console, I can't launch the Apex remote code.

 

I made some investigation on that. Apparently, the js code is running because I can console.log() some variables, but the call of MyExtension.myMethod doesn't work.

 

The js code :

 

var var1 = 'value1';
var var2 = 'value2';

console.log(var1);
console.log(var2); MyExtension.myMethod(var1, var2, function(result, event) { if(event.status) { console.log("Update successful"); } else { console.log("Update unsuccessful"); } }, {escape:true});

cosole.log('test');

 

The Apex code :

global with sharing class MyExtension {
	@RemoteAction
	global static void myMethod(String var1, String var2) {
		// my logic
	}
}

 

Even the console.log('test') works, but the console.log('Update successful') or console.log(Update unsuccessful') does not appear... Plus, I don't get any Debug log about that remoting.

 

There is no need to see my logic because like I said it works perfectly in standard.

 

Is there any other ways to detect cosole tab or subtab closing and call some Apex logic ?

 

Thank you !

Val ValinoVal Valino

Try something like this:

 

Visualforce.remoting.Manager.invokeAction(
'{!$RemoteAction.MyExtension.myMethod}',
var1, var2,
function(result, event) {
if(event.status) {
console.log("Update successful");
}
else {
console.log("Update unsuccessful");
}
}, {escape:true});

 

 

 

 

Also, you won't get debug logs for Javascript remoting. You will get it in the browser console log.

jgaiottojgaiotto

Hi,

 

thank you for your response, but it still doesn't work.

 

The js function is still called, but the remoting is not. I am just able to see the console.log() in the browser console before and after the remote call.

 

Btw, I call some remoting on page load, and I can see it in the debug log.

 

I was thinking, does this have something to do with the fact that my 2 Apex functions are in the same controller extension ?

Val ValinoVal Valino

I'm not sure. It should work and it doesn't matter that both apex methods are in the same controller extension.

jgaiottojgaiotto

I just read again my question, and I am not sure I am very clear.

 

The remote call works fine in a classic application, but when I try to use it in a Service Cloud Console application, it doesn't work.

 

I can't call javascript remoting when I close a tab or a subtab of the service cloud console.

 

Is there a way to detect it ? Thanks

jgaiottojgaiotto

Just an update to say I am now using th following js function :

sforce.apex.execute("MyClass","myFuncion",{var1: value1, var2: value2});

 to call Apex on body before unload.

 

It now works fine on Chrome, when I close a service cloud console tab or subtab.

 

But Firefox doesn't consider that as a body unload, so the call won't happen... It only works when I close a browser tab.

 

Any idea on how to detect service cloud console tab/subtab closing on every browser ? Didn't SFDC implement a function or a handler ?

 

Thanks guys.

JayseJayse

Hi 

 

Did you make any further progress on this?

 

I have a requirement to create the same (catch when a user closes a primary tab in the console), it looks like there is no simple way to do this.

 

Thanks

jgaiottojgaiotto
No, unfortunately, I did not... :(
NHANHA
Hi,

Any news on this issue ?
Does anyone make any progress ?

Thanks
Najib