Last active
January 22, 2019 14:18
-
-
Save MashmatrixSupport/c92aa2f45dd700bff98bdc019f5fec1e to your computer and use it in GitHub Desktop.
カスタムアクション
This file contains 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
public with sharing class CustomActionController { | |
public Account[] accounts { get; set; } | |
public CustomActionController() { | |
// 「URLを開く」アクションボタンの詳細設定で指定したパラメータに選択したレコードの値が渡される | |
String idParam = ApexPages.currentPage().getParameters().get('id'); | |
if (idParam != null) { | |
// 「URLを開く」アクションボタンの詳細設定で"配列値のシリアライズ方法に「コンマ区切り」を選んでいる場合 | |
String[] ids = idParam.split(','); | |
accounts = [SELECT Id, Name FROM Account WHERE Id IN :ids]; | |
} | |
} | |
public void executeUpdate() { | |
// 何らかの処理を実行 | |
if (accounts != null) { | |
for (Account acc: accounts) { | |
acc.OwnerId = UserInfo.getUserId(); | |
} | |
update accounts; | |
accounts = null; | |
} | |
} | |
} |
This file contains 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="CustomActionController" tabStyle="Account" lightningStylesheets="true"> | |
<apex:form> | |
<apex:sectionHeader title="Custom Action" /> | |
<apex:pageBlock title="Update Accounts"> | |
<ul> | |
<apex:repeat value="{!accounts}" var="acc"> | |
<li>{!acc.Name}</li> | |
</apex:repeat> | |
</ul> | |
<apex:pageBlockButtons> | |
<apex:commandButton rendered="{!accounts != null}" action="{!executeUpdate}" value="Update" /> | |
<apex:commandButton rendered="{!accounts == null}" onClick="window.top.close();" value="Close" /> | |
</apex:pageBlockButtons> | |
</apex:pageBlock> | |
</apex:form> | |
</apex:page> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment