You need to sign in to do that
Don't have an account?
Parvinder Chana
Show custom button (execute java script) on visual force page
Hello all,
I created a custom button on Case object and purpose of the button is to escalate the case. Here is the code and it works great.
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")}
var caseObj = new sforce.SObject("Case");
caseObj.id = '{!Case.Id}'; /* Need Id field to update Case */
if ({!Case.IsEscalated} == 0)
{
caseObj.IsEscalated= 1;
};
/* Change escalated field */
/* update method takes an array of Cases; init to 1 element - 'caseObj' */
var result = sforce.connection.update([caseObj]);
if (result[0].success == 'false') {
alert(result[0].errors.message);
}
}
Now I want to use this custom button in visual force page and add that VF page on feed view, this is what I did with VF page:
<apex:page standardController="Case" extensions="CaseController" tabStyle="Case" >
<apex:form >
<apex:commandButton action="{!URLFOR($Action.Case.Escalate, Case.Id)}" value="Escalate"/>
</apex:form>
</apex:page>
I added above VF page on feed view layout and it shows up the custom button as seen below
but when I click the button, it doesn't execute the java scripts and shows the following windows after button click
Thanks in advance for help!
P
I created a custom button on Case object and purpose of the button is to escalate the case. Here is the code and it works great.
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")}
var caseObj = new sforce.SObject("Case");
caseObj.id = '{!Case.Id}'; /* Need Id field to update Case */
if ({!Case.IsEscalated} == 0)
{
caseObj.IsEscalated= 1;
};
/* Change escalated field */
/* update method takes an array of Cases; init to 1 element - 'caseObj' */
var result = sforce.connection.update([caseObj]);
if (result[0].success == 'false') {
alert(result[0].errors.message);
}
}
Now I want to use this custom button in visual force page and add that VF page on feed view, this is what I did with VF page:
<apex:page standardController="Case" extensions="CaseController" tabStyle="Case" >
<apex:form >
<apex:commandButton action="{!URLFOR($Action.Case.Escalate, Case.Id)}" value="Escalate"/>
</apex:form>
</apex:page>
I added above VF page on feed view layout and it shows up the custom button as seen below
but when I click the button, it doesn't execute the java scripts and shows the following windows after button click
Thanks in advance for help!
P
public with sharing class Parvinder_CaseController {
public ApexPages.StandardController stdController;
public Parvinder_CaseController(ApexPages.StandardController Controller) {
stdController =Controller;
}
public void Escalate(){
Case C = (Case)stdController.getRecord();
Case CUpd = new Case();
CUpd.Id= C.Id;
CUpd.Status='High';
update CUpd;
}
}
All Answers
public with sharing class Parvinder_CaseController {
public ApexPages.StandardController stdController;
public Parvinder_CaseController(ApexPages.StandardController Controller) {
stdController =Controller;
}
public void Escalate(){
Case C = (Case)stdController.getRecord();
Case CUpd = new Case();
CUpd.Id= C.Id;
CUpd.Status='High';
update CUpd;
}
}
Cheers!
P