Last active
June 1, 2018 11:35
-
-
Save Sunil02kumar/4f9d96ddb93ab8ee4f0913bed238ea02 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global class AccountUtility implements OnClickJSUtilityController.OnClickJSHelper{ | |
global OnClickJSUtilityController.onClickJSMessageWrapper executeLogic(string accountId){ | |
OnClickJSUtilityController.onClickJSMessageWrapper wrap = new OnClickJSUtilityController.onClickJSMessageWrapper(); | |
if(accountid!=null && accountId!=''){ | |
try{ | |
Account acc=[select id,name,type,billingCountry,BillingPostalCode from Account where id=:accountId]; | |
if(acc.BillingPostalCode!=null && acc.BillingPostalCode!='' && acc.billingCountry!=null && acc.billingCountry!=''){ | |
acc.type='Prospect'; | |
update acc; | |
wrap.successMsg ='Operation successfully completed'; | |
wrap.isOperationSuccessfull=true; | |
}else{ | |
wrap.errmsg ='Please specify billing country and postal code before converting account to prospect.'; | |
wrap.isOperationSuccessfull=false; | |
} | |
}catch(exception ex){ | |
wrap.errmsg ='Something went wrong. Please contact your system administrator.Error details: '+ex.getmessage(); | |
wrap.isOperationSuccessfull=false; | |
} | |
wrap.redirectUrl='/'+accountId; | |
} | |
return wrap; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global class OnClickJSUtilityController { | |
global string recordId{get;set;} | |
global string apexClassName{get;set;} | |
global onClickJSMessageWrapper operationLog{get;set;} | |
global OnClickJSUtilityController(){ | |
recordId = ApexPages.currentPage().getParameters().get('rid'); | |
apexClassName = ApexPages.currentPage().getParameters().get('cname'); | |
operationLog = new onClickJSMessageWrapper(); | |
} | |
@RemoteAction | |
global static onClickJSMessageWrapper performLogic(string recordId,string className){ | |
onClickJSMessageWrapper operationLog = new onClickJSMessageWrapper(); | |
if(className!='' && className!=null && recordId!='' && recordId!=null){ | |
Type classType = Type.forName(className); | |
if(classType!=null){ | |
OnClickJSHelper obj = (OnClickJSHelper)classType.NewInstance(); | |
operationLog= obj.executeLogic(recordId); | |
} | |
} | |
system.debug('*******operationLog'+operationLog); | |
return operationLog; | |
} | |
global class onClickJSMessageWrapper{ | |
global string successMsg; | |
global string errmsg; | |
global boolean isOperationSuccessfull; | |
global string redirectUrl; | |
global onClickJSMessageWrapper(){ | |
isOperationSuccessfull = false; | |
successMsg =''; | |
errmsg=''; | |
redirectUrl=''; | |
} | |
} | |
global Interface OnClickJSHelper{ | |
onClickJSMessageWrapper executeLogic(string recordId); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page controller="OnClickJSUtilityController" showHeader="false" standardStylesheets="false" sidebar="false" > | |
<head> | |
<!-- Import the Design System style sheet --> | |
<apex:slds /> | |
<script> | |
var recid = '{!recordId}'; | |
var className = '{!apexClassName}'; | |
var redirectURLAfterAction=''; | |
window.onload = function() { | |
showHideSpinner(true); | |
callexecuteLogic(); | |
} | |
function showHideSpinner(str){ | |
console.log('*****str:'+str); | |
if(str){ | |
document.getElementById('spinnerdiv').style.display='block'; | |
}else{ | |
document.getElementById('spinnerdiv').style.display='none'; | |
} | |
} | |
function redirectToRecordDetailPage(){ | |
if(redirectURLAfterAction!=''){ | |
window.top.location.href = redirectURLAfterAction; | |
}else{ | |
window.top.location.href = "/"+recid; | |
} | |
} | |
function callexecuteLogic(){ | |
Visualforce.remoting.Manager.invokeAction( | |
'{!$RemoteAction.OnClickJSUtilityController.performLogic}', | |
recid,className, | |
function(result, event){ | |
if (event.status) { | |
showHideSpinner(false); | |
console.log('**result-'+ JSON.stringify(result)); | |
//alert('**result-'+ JSON.stringify(result)); | |
var headerText=''; | |
if(result.isOperationSuccessfull){ | |
headerText ='Confirmation'; | |
finalSuccessConfirmationBox(result.successMsg,headerText); | |
}else{ | |
headerText ='Error'; | |
finalSuccessConfirmationBox(result.errmsg,headerText); | |
} | |
redirectURLAfterAction=result.redirectUrl; | |
}else { | |
alert('Some problem occurred. Please contact system administrator.'+event.message); | |
showHideSpinner(false); | |
redirectToRecordDetailPage(); | |
} | |
}, | |
{escape: true} | |
); | |
} | |
function finalSuccessConfirmationBox(messagestr,headerValue){ | |
document.getElementById('popUpDivForConfirmation').style.display='block'; | |
document.getElementById('popupheadertext').innerHTML = headerValue; | |
var btnElement = document.getElementById('confirmButtonOnPopup'); | |
btnElement.innerHTML = 'Ok'; | |
btnElement.onclick = function() { // Note this is a function | |
redirectToRecordDetailPage(); | |
}; | |
var cancelBtnElement = document.getElementById('cancel_btn_id'); | |
cancelBtnElement.style.display='none'; | |
var closeIconElement = document.getElementById('close_pop_icon'); | |
closeIconElement.style.display='none'; | |
var filepopupSectiondivStr = document.getElementById('popUpContentDiv'); | |
filepopupSectiondivStr.innerHTML=messagestr; | |
} | |
</script> | |
</head> | |
<body> | |
<div > | |
<!--pop up section starts--> | |
<div class="slds-grid slds-wrap" id="popUpDivForConfirmation" style="display: none;"> | |
<div class="slds-col slds-size--1-of-1 slds-small-size--1-of-1 slds-medium-size--1-of-1 slds-col"> | |
<div role="dialog" tabindex="-1" class="slds-modal slds-fade-in-open"> | |
<div class="slds-modal__container"> | |
<div class="slds-modal__header" > | |
<button id="close_pop_icon" onclick="closePopUpScreen()" class="slds-button slds-button_icon slds-modal__close slds-button_icon-inverse" title="Close"> | |
<svg class="slds-button__icon slds-button__icon_large" > | |
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/apexpages/slds/latest/assets/icons/utility-sprite/svg/symbols.svg#close" /> | |
</svg> | |
<span class="slds-assistive-text">Close</span> | |
</button> | |
<h2 id="popupheadertext" class="slds-text-heading--medium"></h2> | |
</div> | |
<div class="slds-modal__content slds-p-around--medium"> | |
<div class="slds-align_absolute-center" id="popUpContentDiv" > | |
</div> | |
</div> | |
<div class="slds-modal__footer"> | |
<button id="cancel_btn_id" class="slds-button slds-button_neutral" onclick="closePopUpScreen()">Cancel</button> | |
<button id="confirmButtonOnPopup" class="slds-button slds-button_neutral" ></button> | |
</div> | |
</div> | |
</div> | |
<div class="slds-backdrop slds-backdrop--open"></div> | |
</div> | |
</div> | |
<!--pop up section ends--> | |
</div> | |
<!--code for spinner--> | |
<div id="spinnerdiv" class="demo-only demo--inverse" style="display:none;"> | |
<div class="slds-spinner_container"> | |
<div role="status" class="slds-spinner slds-spinner_medium"> | |
<span class="slds-assistive-text">Loading</span> | |
<div class="slds-spinner__dot-a"></div> | |
<div class="slds-spinner__dot-b"></div> | |
</div> | |
</div> | |
</div> | |
<!--code for spinner ends--> | |
</body> | |
</apex:page> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment