728x90
표준 및 사용자 정의 오브젝트 탭 목록에서 여러 건을 한 번에 삭제하기 위해서는 Visualforce와 Apex Class로 개발이 필요합니다.
여기서는 Lotto__c 라는 Custom Object를 예제로 사용하였습니다.
MassDeleteExtension.apxc
public with sharing class MassDeleteExtension {
ApexPages.StandardSetController setCon;
public String error { get; set; }
public PageReference originalUrl { get; set; }
public MassDeleteExtension(ApexPages.StandardSetController controller) {
setCon = controller;
}
public String getMySelectedSize() {
return setCon.getSelected().size() + '';
}
public PageReference deleteRecords(){
originalUrl = setCon.cancel();
delete setCon.getSelected();
return originalUrl;
}
}
MassDeleteExtension_TEST.apxc
@isTest
public with sharing class MassDeleteExtension_TEST {
static testMethod void testDeleteRecords() {
List<lotto__c> objs = new List<lotto__c>();
ApexPages.StandardSetController sc = new ApexPages.StandardSetController(objs);
MassDeleteExtension extension = new MassDeleteExtension(sc);
System.assertNotEquals(null, extension.deleteRecords());
}
static testMethod void testSelectedSize() {
List<lotto__c> objs = new List<lotto__c>();
objs.add(new lotto__c(Name='1'));
ApexPages.StandardSetController sc = new ApexPages.StandardSetController(objs);
sc.setSelected(objs);
MassDeleteExtension extension = new MassDeleteExtension(sc);
System.assertEquals('1', extension.getMySelectedSize());
}
}
MassDeleteVf_Lotto.vfp
Object에 맞게 standardController="<sObject>" 에서 <sObject> 부분만 변경해서 생성하여 줍니다.
<apex:page extensions="MassDeleteExtension"
standardController="Lotto__c"
recordSetVar="sobjects"
standardStylesheets="false"
sidebar="false"
applyBodyTag="false"
docType="html-5.0">
<html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<head>
<apex:slds />
</head>
<body class="slds-scope">
<div class="demo-only" style="height:24rem">
<section role="alertdialog" tabindex="0" aria-labelledby="prompt-heading-id" aria-describedby="prompt-message-wrapper" class="slds-modal slds-fade-in-open slds-modal_prompt" aria-modal="true">
<div class="slds-modal__container">
<header class="slds-modal__header slds-theme_error slds-theme_alert-texture">
<button class="slds-button slds-button_icon slds-modal__close slds-button_icon-inverse" title="Close">
<svg class="slds-button__icon slds-button__icon_large" aria-hidden="true">
<use xlink:href="/assets/icons/utility-sprite/svg/symbols.svg#close"></use>
</svg>
<span class="slds-assistive-text">Close</span>
</button>
<h2 class="slds-text-heading_medium" id="prompt-heading-id">삭제 확인</h2>
</header>
<div class="slds-modal__content slds-p-around_medium" id="prompt-message-wrapper">
<p>선택한 {!mySelectedSize}개 레코드를 삭제하시겠습니까?</p>
</div>
<footer class="slds-modal__footer slds-theme_default">
<apex:form >
<apex:commandLink action="{!cancel}" value="" id="cancel"><button class="slds-button slds-button--neutral">취소</button></apex:commandLink>
<apex:commandLink action="{!deleteRecords}" value="" id="delete"><button class="slds-button slds-button_destructive">삭제</button></apex:commandLink>
</apex:form>
</footer>
</div>
</section>
<div class="slds-backdrop slds-backdrop_open"></div>
</div>
</body>
</html>
</apex:page>
1. 설정 > 개체 관리자 에서 해당 오브젝트(Lotto__c)의 버튼, 링크 및 작업 메뉴에서 새 버튼 또는 링크를 클릭하여 아래와 같이 등록 합니다.
2. 등록된 버튼이 아래와 같이 보입니다.
3. Salesforce Classic의 레이아웃 검색 메뉴에서 목록 보기의 편집을 클릭합니다.
4. 사용자 정의 버튼 섹션에서 앞에서 추가한 대량 삭제 버튼을 선택한 버튼 쪽으로 옮기고 저장을 합니다.
5. 해당 오브젝트 목록에 앞에서 추가한 대량 삭제 버튼이 보이고 이제 삭제할 레코드들을 체크하고, 대량 삭제 버튼을 클릭합니다.
6. 앞에서 선택한 항목의 레코드 개수가 표시되며 삭제 여부를 다시 한번 확인합니다.
삭제 버튼을 클릭하면 삭제가 되고 이전 목록 페이지로 이동합니다.
취소 버튼을 클릭하면 이전 목록 페이지로 이동합니다.
마치며, 해당 작업은 필요한 오브젝트 별로 Visualforce 페이지는 추가로 생성하여 설정이 필요합니다.
그리고 레코드를 대량으로 삭제하는 만큼 주의가 필요합니다.
728x90
'Salesforce > Development' 카테고리의 다른 글
Apex에서 종속 선택 목록 값 가져오기 (Get Dependent Picklist Values in Apex) (0) | 2022.04.20 |
---|---|
Safe Navigation Operator 안전 탐색 연산자(?.) (0) | 2022.04.19 |
String.isEmpty() & String.isBlank() & String.isNotEmpty() & String.isNotBlank() 차이점 (0) | 2022.04.18 |
세일즈포스 사용자 정의 알림 (Salesforce Custom Notification) 설정 및 구현 (0) | 2021.04.13 |
Custom Label Parameter (1) | 2019.12.02 |