在对应的页面新建对应的Button或者Action
使用Visualforce 进行获取
<apex:page standardController="Account" recordSetVar="accounts"
extensions="CustomerVisitPlanListViewController" action="{!redirect}">
<script>
window.onload = setupPage;
function setupPage() {
var records = {!selectedAccounts};
console.log(records);
if (records.length === 0) {
sforce.one.showToast({
'title': 'Alert!',
'message': 'Please select at least one account.',
'type': 'warning',
});
window.history.go(-1)
}
}
</script>
</apex:page>
Apex
public class CustomerVisitPlanListViewController{
public List<Account> selectedAccounts {
get; set;
}
private ApexPages.StandardSetController standardController;
public CustomerVisitPlanListViewController(ApexPages.StandardSetController standardController) {
this.standardController = standardController;
this.selectedAccounts = standardController.getSelected();
}
public PageReference redirect() {
List<Account> selectedAccount = (List<Account>) standardController.getSelected();
String accountIds = '';
for (Integer i = 0; i < selectedAccount.size(); i++) {
if (i != selectedAccount.size() - 1) {
accountIds += selectedAccount[i].Id + ',';
} else {
accountIds += selectedAccount[i].Id;
}
}
PageReference pageRef;
if (selectedAccount.size() != 0) {
pageRef = new PageReference('/lightning/cmp/c__AccountPlan');
pageRef.getParameters().put('c__accountList', accountIds);
pageRef.setRedirect(true);
return pageRef;
}
return null;
}
public PageReference updateCases() {
return standardController.save();
}
}
获取到选中的Account
组件controller进行解析
({
onInit: function(cmp, event, helper) {
if (cmp.get('v.pageReference') && cmp.get('v.pageReference').state) {
const accountListString = cmp.get('v.pageReference').state.c__accountList;
let accountList = accountListString.split(',');
cmp.set('v.selectedCustomerId', accountList);
} else {
//赋值到cmp 组件selectedCustomerId List 中
cmp.set('v.selectedCustomerId', [cmp.get('v.recordId')]);
}
}
});