bbc

abcd·2024년 10월 14일

test22

목록 보기
2/6

/**

  • @description :

  • @author : ChangeMeIn@UserSettingsUnder.SFDoc

  • @group :

  • @last modified on : 10-14-2024

  • @last modified by : ChangeMeIn@UserSettingsUnder.SFDoc
    **/
    public with sharing class zzgrindapex {

    @AuraEnabled(cacheable=true)
    public static grid_test__mdt getMyGridData() {
        List<grid_test__mdt> gridgo = [SELECT Header__c, Inactive__c FROM grid_test__mdt];
    
        if (gridgo.isEmpty()) {
            return null; // 데이터가 없을 경우 null 반환
        }
    
        String a = gridgo.get(0).Header__c;
    
        List<Object> b;
        List<String> customFieldValues = new List<String>(); // customfield 값을 저장할 리스트
    
        try {
            b = (List<Object>) JSON.deserializeUntyped(a);
            System.debug('Parsed JSON: ' + b);
    
            // 각 요소에서 customfield 값을 가져오기
            for (Object obj : b) {
                Map<String, Object> item = (Map<String, Object>) obj;
                if (item.containsKey('customfield')) {
                    String customFieldValue = (String) item.get('customfield');
    
                    String labelValue;
                    try {
                        labelValue = (String) System.Label.get(customFieldValue);
                    } catch (Exception e) {
                        labelValue = null; // 레이블이 존재하지 않으면 null
                    }
                    
                    // null 체크 후 리스트에 추가
                    if (labelValue != null) {
                        customFieldValues.add(labelValue);
                    }
                }
            }
    
            System.debug('Custom Field Values: ' + customFieldValues);
        } catch (Exception e) {
            System.debug('JSON parsing error: ' + e.getMessage());
            b = new List<Object>(); // 오류 발생 시 빈 리스트
        }
    
        return gridgo.get(0); // 예시로 첫 번째 데이터 반환
    }

    }

0개의 댓글