Java Script Button:
{!REQUIRESCRIPT(“/soap/ajax/24.0/connection.js”)}
{!REQUIRESCRIPT(“/soap/ajax/24.0/apex.js”)}
try{
var accountId='{!Account.Id}’;
var result = sforce.apex.execute(“UpdateAccount”, “updateEnable”,{accId: accountId});
{Controller} {Method}
location.reload();
}
catch(err) {
txt=”There was an error on this page.\n\n”;
txt+=”Error description: ” + err.description + “\n\n”;
txt+=”Click OK to continue.\n\n”;
alert(txt);
}
======================================
Controller class start with global when you calling class from Javascript button.
global class UpdateAccount {
webService static string updateEnable(List<Id> accId){
try{
System.debug(‘Id–>’+accId);
if(accId != NULL && accId.size() > 0)
{
Account accUpdate = [SELECT Id, Enable__c from Account where Id =:accId];
accUpdate.Enable__c = ‘true’;
update accUpdate;
return ‘Updated successfully’;
}
}
catch(exception e){}
return null;
}
}
{!REQUIRESCRIPT(“/soap/ajax/24.0/connection.js”)}
{!REQUIRESCRIPT(“/soap/ajax/24.0/apex.js”)}
try{
var accountId='{!Account.Id}’;
var result = sforce.apex.execute(“UpdateAccount”, “updateEnable”,{accId: accountId});
{Controller} {Method}
location.reload();
}
catch(err) {
txt=”There was an error on this page.\n\n”;
txt+=”Error description: ” + err.description + “\n\n”;
txt+=”Click OK to continue.\n\n”;
alert(txt);
}
======================================
Controller class start with global when you calling class from Javascript button.
global class UpdateAccount {
webService static string updateEnable(List<Id> accId){
try{
System.debug(‘Id–>’+accId);
if(accId != NULL && accId.size() > 0)
{
Account accUpdate = [SELECT Id, Enable__c from Account where Id =:accId];
accUpdate.Enable__c = ‘true’;
update accUpdate;
return ‘Updated successfully’;
}
}
catch(exception e){}
return null;
}
}