I created a Visualforce page to override the standard case view page. I have a custom button "OnlineClosed" on case object that ask for a remark and update 2 field status and stage at case object. The button works fine on the standard case view page, but not at my visualforce page. Does anyone have any idea why this button does not working on the visualforce page? When I click on it, I get a error message "URL No Longer Exists".

About Custom Button Behavior: Execute JavaScript and Content Source: OnClick JavaScript.

var url = parent.location.href; 
var updateRecord = new Array(); 
var myquery = "SELECT Id FROM Case WHERE Id = '{!Case.Id}' limit 1"; 
var reason = prompt("Enter reason", ""); 
result = sforce.connection.query(myquery); 
records = result.getArray("records"); 
var update_Case = records[0]; 
update_Case.Status = "Closed"; 
update_Case.Stage__c= "Resolved"; 
update_Case.Remark__c= reason; 
result = sforce.connection.update(updateRecord); 
parent.location.href = url;

Code for Button on VisualForce page is below.

1 Answer 1


Custom buttons are used on Standard page layouts. I am not sure how are you using the same on a VF page.

If you want to replicate the same behavior, better write a function in the VF page and call this function onClick event of an apex:commandbutton. Something like this:

<script  src="/soap/ajax/25.0/connection.js" type="text/javascript"></script>
<script  src="/soap/ajax/25.0/apex.js" type="text/javascript"></script>

function updaterecord(){
var updateRecord = [];
var case = new sforce.SObject("Case"); 
case.id = "{!Case.Id}";
var reason = prompt("Enter reason", "");    
case.Status = "Closed"; 
case.Stage__c= "Resolved"; 
case.Remark__c= reason; 

result = sforce.connection.update(updateRecord); 

<apex:commandButton value="Update"  onclick=" return updaterecord();" reRender="pageDetails" />

You may need to make some more tweaks but I know you can do that. Let me know if this way works for you.

  • on button click it will not ask for remark and it will also not update status and stage field value at case object. pl check Commented May 28, 2015 at 9:12
  • Now it's working I changed var name from case to c (var case = new sforce.SObject("Case");), thanks heisenberg for your good time to resolve my problem. Commented May 28, 2015 at 9:41
  • Thats great.... Commented May 28, 2015 at 9:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .