SalesforceのClassicでOnClick JavaScriptボタンをLightning Experienceに移行する際にその方法の一つを共有します。
1.詳細ボタンの場合
Classic:
window.open(“/apex/Test_VF?id=”+ ids, “_blank”);
Lightning Experience:
window.location.href = '/apex/Test_VF?id={!ids}';
2.リストビューボタンの場合
Classic:
var ids = {!GETRECORDIDS($ObjectType.Test__c)};
if (ids.length === 0) {
alert('None');
} else {
var test_url = '{!URLFOR("/apex/Test_VF?id=")}' ;
window.open(test_url + ids, 'Test');
}
Lightning Experience:
<script type="text/javascript">
var __sfdcSessionId = '{!GETSESSIONID()}';
</script>
<script src="../../soap/ajax/44.0/connection.js" type="text/javascript"></script>
<script src="../../soap/ajax/44.0/apex.js" type="text/javascript"></script>
<script type="text/javascript">
var ids = "<apex:repeat value="{!selected}" var="obj">{!obj.Id},</apex:repeat>".slice(0,-1).split(',');
if (ids[0] == "") {
alert('None');
history.back();
} else {
window.location.href = '/apex/Test_VF?id='+ids;
}
</script>