Progress bar for custom button on click salesforce
{!REQUIRESCRIPT("/soap/ajax/36.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/36.0/apex.js")}
var CaseId = '{!Case.Id}';
var sta= '{!Case.status}';
if(sta){
var result=sforce.apex.execute("ApexClassName","Method",{CaseId:CaseId});
var overlay = document.createElement('overlay');
overlay.style.background = '#000';
overlay.style.position = 'absolute';
overlay.style.top='0px';
overlay.style.bottom = '0px';
overlay.style.right = '0px';
overlay.style.left = '0px';
overlay.style.zIndex = '1000';
overlay.style.opacity='0.7';
var loading = document.createElement('img');
loading.src = 'https://c.na5050.content.force.com/servlet/servlet.ImageServer?id=014446000001yJpw&oid=00De2323340uNx0';
loading.style.position = 'absolute';
loading.style.top='50%';
loading.style.left = '50%';
loading.style.zIndex = '1000';
overlay.appendChild(loading);
document.body.appendChild(overlay);
if(result!=null && result!='success'){
document.body.removeChild(overlay);
var outerdiv = document.createElement('div');
outerdiv.innerHTML = result;
outerdiv.style.display = 'inline-block';
outerdiv.style.fontSize ='14px';
outerdiv.style.color = 'red';
//outerdiv.style.border = '1px solid grey';
outerdiv.style.padding = '10px';
var mainDiv = document.createElement('div');
mainDiv.style.marginLeft = '30%';
mainDiv.style.marginTop = '10px';
mainDiv.appendChild(outerdiv);
document.getElementById('errorDiv_ep').innerHTML = result;
document.getElementById('errorDiv_ep').style.display='';
setTimeout(function(){
document.getElementById('errorDiv_ep').innerHTML = '';
document.getElementById('errorDiv_ep').style.display='none';
},5000);
}else{
document.location.reload(true);
}
}else{
alert('You can not revert back the case to Queue.');
document.getElementById('errorDiv_ep').innerHTML = 'You can not close the case.';
document.getElementById('errorDiv_ep').style.display='';
setTimeout(function(){
document.getElementById('errorDiv_ep').innerHTML = '';
document.getElementById('errorDiv_ep').style.display='none';
},5000);
}
{!REQUIRESCRIPT("/soap/ajax/36.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/36.0/apex.js")}
var CaseId = '{!Case.Id}';
var sta= '{!Case.status}';
if(sta){
var result=sforce.apex.execute("ApexClassName","Method",{CaseId:CaseId});
var overlay = document.createElement('overlay');
overlay.style.background = '#000';
overlay.style.position = 'absolute';
overlay.style.top='0px';
overlay.style.bottom = '0px';
overlay.style.right = '0px';
overlay.style.left = '0px';
overlay.style.zIndex = '1000';
overlay.style.opacity='0.7';
var loading = document.createElement('img');
loading.src = 'https://c.na5050.content.force.com/servlet/servlet.ImageServer?id=014446000001yJpw&oid=00De2323340uNx0';
loading.style.position = 'absolute';
loading.style.top='50%';
loading.style.left = '50%';
loading.style.zIndex = '1000';
overlay.appendChild(loading);
document.body.appendChild(overlay);
if(result!=null && result!='success'){
document.body.removeChild(overlay);
var outerdiv = document.createElement('div');
outerdiv.innerHTML = result;
outerdiv.style.display = 'inline-block';
outerdiv.style.fontSize ='14px';
outerdiv.style.color = 'red';
//outerdiv.style.border = '1px solid grey';
outerdiv.style.padding = '10px';
var mainDiv = document.createElement('div');
mainDiv.style.marginLeft = '30%';
mainDiv.style.marginTop = '10px';
mainDiv.appendChild(outerdiv);
document.getElementById('errorDiv_ep').innerHTML = result;
document.getElementById('errorDiv_ep').style.display='';
setTimeout(function(){
document.getElementById('errorDiv_ep').innerHTML = '';
document.getElementById('errorDiv_ep').style.display='none';
},5000);
}else{
document.location.reload(true);
}
}else{
alert('You can not revert back the case to Queue.');
document.getElementById('errorDiv_ep').innerHTML = 'You can not close the case.';
document.getElementById('errorDiv_ep').style.display='';
setTimeout(function(){
document.getElementById('errorDiv_ep').innerHTML = '';
document.getElementById('errorDiv_ep').style.display='none';
},5000);
}