I'm trying to create a button which will:

1) change case status to resolved
2) reload primary tab in service console or refresh a page in classical UI

BUT I'm getting an error
Refused to set unsafe header 'User Agent'
and the field is changed but primary tab isn't refreshed, but after manually reloading a page, I can see the change; in classical UI everything works except firing the same error. (BTW I'm using Chrome, latest version).

How to fix it? Adding a button seems like an easy task.

Here's my code:


sforce.connection.sessionId = '{!GETSESSIONID()}';

var c = new sforce.SObject("Case"); 
c.id = "{!Case.Id}"; 
c.Status = 'Resolved'; 

result = sforce.connection.update([c]); 

if (sforce.console.isInConsole()) {
} else {

var refreshTab = function (tab) {
    if (tab.success) {
        sforce.console.refreshPrimaryTabById(tab.id, true);
  • 1
    have you tried replacing that with sforce.connection.sessionId = '{!GETSESSIONID()}'; with sforce.connection.sessionId= '{!$Api.Session_ID}'; ?? – AlphaBravo Jun 13 '16 at 18:06
  • @AlphaBravo you made my day!. Thanks. But I'm completely out of any ideas why it worked. There's no longer a user agent error. And it works in service console. Could you tell why? Any resources to read about sessionId? – NGix Jun 13 '16 at 18:53

sforce.connection.sessionId= '{!$Api.Session_ID}'; will work for you.

My understanding is $API.Session_ID is a global variable that the system will pull when you execute a button.(https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_variables_global_api.htm). When you use GETSESSIONID(), it is a visualforce function that's available on visualforce pages.(https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_variables_functions.htm)

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.