Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 코딩테스트 연습
- 개인정보보호
- 코딩테스트
- 클라우드
- vagrant
- 시저암호
- 머신러닝
- 회귀분석
- 자료형
- 코테
- docker
- 데이터3법
- 데이터분석
- AWS
- 도커
- 마이데이터
- 웹모의해킹
- 데이터 분석
- 파이썬 문법
- AI
- 웹 모의해킹
- XSS 취약점
- 백준
- 개인정보보호법
- 함수
- 알고리즘
- 프로그래머스
- 컴퓨터 구조
- 정보보안
- 파이썬
Archives
- Today
- Total
찬란하게
Salesforce 주요 Annotation 본문
1. @AuraEnabled
LWC(Apex와 Lightning Web Components 간의 데이터 통신) 및 Aura Components와 Apex 메서드 간 통신에 필수.
특징
- Apex 메서드를 Lightning Web Component 또는 Aura에서 호출할 수 있도록 노출.
- 반환값은 클라이언트 측에서 사용할 수 있음.
- 옵션: (cacheable=true)로 데이터를 읽기 전용으로 설정 가능.
사용법
public with sharing class AccountService {
@AuraEnabled(cacheable=true)
public static List<Account> getAccounts() {
return [SELECT Id, Name FROM Account];
}
}
2. @InvocableMethod
Flow 및 Process Builder에서 Apex 메서드를 호출할 수 있도록 설정.
특징
- Flow 또는 Process Builder에서만 사용 가능.
- 메서드는 public static으로 선언해야 함.
- 단일 파라미터만 허용하며, 이 파라미터는 List 형식이어야 함.
- 반환값은 단일 객체나 List여야 함.
사용법
public with sharing class AccountActions {
@InvocableMethod(label='Create Accounts' description='Creates a list of Accounts')
public static void createAccounts(List<Account> accountsToCreate) {
insert accountsToCreate;
}
}
3. @TestMethod (또는 @isTest)
Apex 테스트 클래스를 작성할 때 사용.
특징
- 테스트 메서드를 정의할 때 필수.
- Governor Limit, 데이터 격리 등을 적용하여 테스트 환경에서 코드를 실행.
- @testSetup 어노테이션과 함께 사용 가능.
사용법
@isTest
public class AccountServiceTest {
@isTest
static void testGetAccounts() {
// 테스트 데이터 준비
Account acc = new Account(Name='Test Account');
insert acc;
// 메서드 실행
List<Account> accounts = AccountService.getAccounts();
// 결과 검증
System.assert(accounts.size() > 0);
}
}
4. @TestSetup
테스트 메서드에 사용할 공통 데이터를 한 번만 생성하여 여러 테스트 메서드에서 재사용.
특징
- 테스트 실행 시간을 줄이고 데이터 중복을 방지.
- 클래스 내 모든 테스트 메서드에서 공통 데이터로 사용 가능.
사용법
@isTest
public class AccountTest {
@testSetup
static void setup() {
Account acc = new Account(Name='Setup Account');
insert acc;
}
@isTest
static void testAccountRetrieval() {
List<Account> accounts = [SELECT Id, Name FROM Account];
System.assertEquals(1, accounts.size());
}
}
5. @Future
비동기 처리를 위한 메서드에 사용.
특징
- 비동기 작업(예: 대량 데이터 처리, 외부 API 호출)을 실행.
- 반환값 없음(void로 선언).
- 주요 제한사항:
- 호출된 메서드는 즉시 실행되지 않을 수 있음.
- 테스트 시 반드시 Test.startTest()와 Test.stopTest()를 사용해야 함.
사용법
public class AsyncService {
@future
public static void updateContacts(Set<Id> contactIds) {
List<Contact> contacts = [SELECT Id, LastName FROM Contact WHERE Id IN :contactIds];
for (Contact contact : contacts) {
contact.LastName = 'Updated';
}
update contacts;
}
}
6. @RemoteAction
Visualforce 페이지에서 Apex 메서드를 JavaScript로 호출하기 위해 사용.
특징
- Apex 메서드를 AJAX 방식으로 호출 가능.
- Static 메서드에서만 사용 가능.
사용법
public class ContactService {
@RemoteAction
public static List<Contact> getContacts() {
return [SELECT Id, Name FROM Contact];
}
}
7. @ReadOnly
데이터 조회 작업에만 사용되며, 데이터베이스 변경이 금지됨.
특징
- 조회 전용 작업에 최적화.
- Salesforce에서 읽기 전용 작업을 위해 Governor Limit을 증가시킴.
사용법
public with sharing class ReadOnlyExample {
@ReadOnly
public static List<Account> getLargeDataset() {
return [SELECT Id, Name FROM Account LIMIT 50000];
}
}
8. @WithSharing / @WithoutSharing
Apex 클래스에서 **공유 규칙(Sharing Rules)**을 적용하거나 무시.
특징
- @WithSharing: 공유 규칙을 적용하여 데이터 접근 제어.
- @WithoutSharing: 공유 규칙을 무시하고 Apex 코드 실행.
- 기본적으로 Apex 클래스는 공유 규칙 적용 여부를 명시하지 않으면 Without Sharing으로 작동.
사용법
public with sharing class AccountService {
public static List<Account> getUserAccounts() {
return [SELECT Id, Name FROM Account];
}
}
9. @Deprecated
기존 메서드 또는 클래스를 더 이상 사용하지 않을 것임을 표시.
특징
- 기존 코드와의 하위 호환성을 유지하기 위해 사용.
- Deprecated된 메서드는 여전히 작동하지만, 향후 릴리스에서 제거될 가능성이 있음.
사용법
@Deprecated
public static void oldMethod() {
System.debug('This method is deprecated');
}
'SaaS > Salesforce Certi' 카테고리의 다른 글
| Salesforce Multitenancy (0) | 2024.11.30 |
|---|---|
| PD1 202407 - 해설#1 Governor Limits (0) | 2024.11.30 |
| Salesforce <-데이터교환-> 외부시스템 (0) | 2024.11.29 |
| Salesforce Apex Testing (0) | 2024.11.29 |
| Salesforce WorkFlow VS Flow (1) | 2024.11.28 |