차슈의 개발 자국

SObject의 모든 필드 값 가져오기 본문

APEX

SObject의 모든 필드 값 가져오기

차슈 2022. 1. 3. 12:55

※ 본 게시물은 초보 개발자가 작성하는 글이므로 다소 잘못된 부분이 있을 수 있습니다. 수정이 필요한 부분은 댓글 부탁드립니다. ^^

 

 

 

 

Lead 오브젝트의 모든 필드 값 가져오기

    SObjectType objType = Schema.getGlobalDescribe().get('Lead');
    Map<String, Schema.SObjectField> objFields = objType.getDescribe().fields.getMap();

 

 

Schema 클래스?

스키마 설명 정보를 가져오는 메소드가 포함되어 있음.

 

 

Schema 메소드?

Schema 메소드는 다음과 같다. 모든 메소드는 static.

 

  • getGlobalDescribe()
    Returns a map of all sObject names (keys) to sObject tokens (values) for the standard and custom objects defined in your organization.
  • describeDataCategoryGroups(sObjectNames)
    Returns a list of the category groups associated with the specified objects.
  • describeSObjects(sObjectTypes)
    Describes metadata (field list and object properties) for the specified sObject or array of sObjects.
  • describeSObjects(SObjectTypes, SObjectDescribeOptions)
    Describes metadata such as field list and object properties for the specified list of SObjects. The default describe option for this method is SObjectDescribeOptions.DEFERRED, which indicates lazy initialization of describe attributes on first use.
  • describeTabs()
    Returns information about the standard and custom apps available to the running user.
  • GroupStructures(pairs)
    Returns available category groups along with their data category structure for objects specified in the request.

 

 

 

getGlobalDescribe()

org에서 정의한 standard 및 custom object에 대한 모든 SObject 이름(key) 와 SObject 토큰(value) 을 map으로 반환.

 

<Signature>

public static Map<String, Schema.SObjectType> getGlobalDescribe()

 

<Return Value>

Map<String, Schema.SObjectType>

 

<Usage>

For more information on accessing SObjects.

 

<Example>

모든 sObject에 대한 접근 --> 모든 sObject 이름(키)과 sObject 토큰(값) 사이의 관계를 나타내는 맵

Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();

 

 

 

sObject의 모든 필드 설명 결과에 대한 접근

 

field describe result의 getMap 메소드를 사용하여 sObject의 모든 필드 이름(키)과 필드 토큰(값) 사이의 관계를 나타내는 맵을 반환.

 

Map<String, Schema.SObjectField> fieldMap = Schema.SObjectType.Account.fields.getMap();

 

 

 

정리

Apex에서 describe information을 사용하는 방법

 

1. 조직의 sObjects에 대한 토큰 list 또는 Map을 생성

2. 액세스할 sObject를 결정

3. sObject에 대한 설명 결과를 생성

4. 필요한 경우 sObject에 대한 필드 토큰 Map을 생성

5. 코드가 액세스해야 하는 필드에 대한 설명 결과를 생성

 

 

Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
Schema.SObjectType t = gd.get('Account');
Schema.DescribeSObjectResult dsr = t.getDescribe();
Map<String, Schema.SObjectField> fieldMap = dsr.fields.getMap();
Schema.DescribeFieldResult dfr = fieldMap.get('Name').getDescribe();

 

 

 

 

 

'APEX' 카테고리의 다른 글

Trigger Context Variables  (0) 2022.04.05
SObject의 모든 필드 값 가져오기2  (0) 2022.01.03
Apex Trigger 2 (자주 보는 오류)  (0) 2021.12.16
Salesforce안에서 외부 사이트 연결  (0) 2021.12.16
JSON Parsing  (0) 2021.12.16
Comments