You need to sign in to do that
Don't have an account?
Mayank Upadhyaya 5
convert javascript button into lightning component
I have a requirement where javascript button need to convert into lightning component . in javascript button there is apex class calling in that apex class we are calling another apex which is calling another queueable apex class. please help me to implement this functionality below is the code
{!requireScript("/soap/ajax/36.0/connection.js")}
{!requireScript("/soap/ajax/36.0/apex.js")}
var mask = document.createElement('div');
var modal = document.createElement('div');
modal.textContent = 'Recreating managed opportunities...';
mask.appendChild(modal);
mask.style.position = 'fixed';
mask.style.top = '0px';
mask.style.bottom = '0px';
mask.style.left = '0px';
mask.style.right = '0px';
mask.style.background = 'rgba(0,0,0,0.5)';
mask.style.zIndex = 5000;
modal.style.width = '250px';
modal.style.marginTop = '200px';
modal.style.boxSizing = 'borderBox';
modal.style.paddingTop = '50px';
modal.style.paddingBottom = '50px';
modal.style.textAlign = 'center';
modal.style.marginLeft = 'auto';
modal.style.marginRight = 'auto';
modal.style.background = 'white';
modal.style.borderRadius = '7px';
document.body.appendChild(mask);
sforce.connection.sessionId = '{!$Api.Session_ID}';
sforce.apex.execute(
'CompositeOpportunityPrintWebservice',
'print',
{
compositeOpportunityIdStrs:['{!Opportunity.Id}']
},
{
onSuccess: function(){ location.reload() },
onFailure: function() {
document.body.removeChild(mask);
window.alert('There was an error recreating the opportunity.');
}
}
);
{!requireScript("/soap/ajax/36.0/connection.js")}
{!requireScript("/soap/ajax/36.0/apex.js")}
var mask = document.createElement('div');
var modal = document.createElement('div');
modal.textContent = 'Recreating managed opportunities...';
mask.appendChild(modal);
mask.style.position = 'fixed';
mask.style.top = '0px';
mask.style.bottom = '0px';
mask.style.left = '0px';
mask.style.right = '0px';
mask.style.background = 'rgba(0,0,0,0.5)';
mask.style.zIndex = 5000;
modal.style.width = '250px';
modal.style.marginTop = '200px';
modal.style.boxSizing = 'borderBox';
modal.style.paddingTop = '50px';
modal.style.paddingBottom = '50px';
modal.style.textAlign = 'center';
modal.style.marginLeft = 'auto';
modal.style.marginRight = 'auto';
modal.style.background = 'white';
modal.style.borderRadius = '7px';
document.body.appendChild(mask);
sforce.connection.sessionId = '{!$Api.Session_ID}';
sforce.apex.execute(
'CompositeOpportunityPrintWebservice',
'print',
{
compositeOpportunityIdStrs:['{!Opportunity.Id}']
},
{
onSuccess: function(){ location.reload() },
onFailure: function() {
document.body.removeChild(mask);
window.alert('There was an error recreating the opportunity.');
}
}
);
Check below examples.
https://help.salesforce.com/s/articleView?id=sf.lcc_javascript_buttons_overview.htm&type=5
https://developer.salesforce.com/forums/?id=9060G0000005NhJQAU
https://www.bayforce.com/wp-content/uploads/2017/10/Bayforce-JavaScript-Lightning-Experience-White-Paper.pdf
Thanks,