binxie
2023-06-19 41625c74ad92b72151f4d1009ea0c791635d9dac
force-app/main/default/classes/MetaDataUtility.cls
@@ -3,8 +3,10 @@
    public static List<Metadata.LayoutSection> GetRecordTypePageLayout(string record_type_id,string objectType){
        
        Map<string,object> mso = null;
        System.debug('rerord 6' + record_type_id + ':' + objectType);
        string layout_name = GetRecordTypePageLayoutName(record_type_id,objectType,UserInfo.getProfileId());
        System.debug('layout 8' + layout_name);
        List<Metadata.LayoutSection>  temp =  GetLayoutSections(objectType,layout_name);
        List<Metadata.LayoutSection>  layoutSectionList = new List<Metadata.LayoutSection>();
        for(Metadata.LayoutSection section : temp){
@@ -24,7 +26,7 @@
    }
    
    /*[{
            "attributes": {
            "attributes": {
                "type": "Layout",
                "url": "/services/data/v53.0/tooling/sobjects/Layout/00h10000009iAb5AAE"
            },
@@ -55,7 +57,8 @@
                }
            }
        }
        System.debug('mso 60' + mso);
        return table_or_enum_id;
    }
    
@@ -87,7 +90,9 @@
    
    
    public static string GetRecordTypePageLayoutName(string record_type_id,string objectType, string profile_id){
      System.debug('objectType 92' + objectType);
        System.debug('profile 93 ' + profile_id);
        if(!string.isBlank(objectType)){
            List<sobject> lso = [SELECT Id, Name, DeveloperName, SobjectType, IsActive, Description, BusinessProcessId FROM RecordType where SobjectType = :objectType];
            if(lso.size()==0){
@@ -116,6 +121,7 @@
            return null;
        }else{
            Map<string,object> mso = (Map<string,object>)JSON.deserializeUntyped(s);
            System.debug('mso 122' + mso);
        
            if(integer.valueOf(mso.get('size')) > 0){
                List<object> records = ((List<object>)mso.get('records'));
@@ -163,7 +169,9 @@
        List<String> componentNameList = new List<String>{object_name+'-'+layout_name};
        //通过Metadata.Operations.retrieve获取metadata
        //Metadata.Layout -> Metadata.LayoutSection -> Metadata.LayoutColumn objects -> Metadata.LayoutItem objects
        System.debug('componentNameList 171: ' + componentNameList);
        List<Metadata.Metadata> componentList = Metadata.Operations.retrieve(Metadata.MetadataType.Layout, componentNameList);
        System.debug('componentList 173 ' + componentList);
        if(componentList?.size() > 0){
            Metadata.Layout layout = (Metadata.Layout) componentList.get(0);
            List<Metadata.LayoutSection> layoutSectionList = layout.layoutSections;