Salesforce

[APEX란?] APEX는 무엇이고 어떻게 사용하나요?

송테이토 2023. 2. 10. 10:24

https://trailhead.salesforce.com/ko/content/learn/modules/apex_database/apex_database_intro

Get Started with Apex

 

Apex 기본 및 데이터베이스

Apex를 사용하여 Salesforce에서 비즈니스 로직을 추가하고 데이터를 조작해 보세요.

trailhead.salesforce.com

 

 

Apex는 무엇인가요?

Apex는 Java와 유사한 구문을 사용하고 데이터베이스 저장 프로시저와 같이 작동하는 프로그래밍 언어입니다. Apex를 통해 개발자는 버튼 클릭, 관련 레코드 업데이트 및 Visualforce 페이지와 같은 시스템 이벤트에 비즈니스 논리를 추가할 수 있습니다
 
 
즉 객체 지향 언어로 자바랑 비슷하긴 하지만 람다, 제네릭스 등 안되는게 많음....
자바 1.6버전인데 이제 고객관리를 더 용이하게 만든 언어같다.
 
신기한건 대소문자를 따로 구분하지 않는다.

 

에이펙스 코드는 클래스와 트리거 두가지 형식 중 하나로 저장된다.


- 클래스 : 내부 클래스와 같은 멤버가 있는 에이펙스 코드, 변수, 메서드, 속성 등.

- 트리거 - 자동으로 실행되는 에이펙스 코드 DML 이벤트를 처리하는 동안 실행됩니다.

• 성공적으로 컴파일된 코드는 Salesforce 데이터베이스에 메타데이터로 저장됩니다.

 

데이터타입

Integer, Double, Long, Date, Datetime, String, ID, Boolean, among others.

특이하게 ID라는 타입이 있다.

Salesforce.com 레코드 ID는 두 가지 형태로 15자와 18자 두가지 형식이 있다.

 
• URL: 18 character (클래식에서는 15)
• Report: 15 character 
• Formula: 15 character (id) or 18 character (CASESAFEID(id))
• List View: 18 character(클래식에서는 15)
• SOAP API: 18 character
• Apex: 18-character
• Visualforce: 18-character
 
 

Apex 컬렉션: 목록

List<String> colors = new List<String>();
 
String[] colors = new List<String>();
 

 

자바랑 똑같이 add해서 추가해주면 된다.

// Create a list and add elements to it in one step
List<String> colors = new List<String> { 'red', 'green', 'blue' };
// Add elements to a list after it has been created
List<String> moreColors = new List<String>();
moreColors.add('orange');
moreColors.add('purple');
 

 

// Get elements from a list
String color1 = moreColors.get(0);
String color2 = moreColors[0];
System.assertEquals(color1, color2);
// Iterate over a list to read elements
for(Integer i=0;i<colors.size();i++) {
    // Write value to the debug log
    System.debug(colors[i]);
}