public without sharing class TestClass
|
{
|
public static List<Metadata.LayoutSection> GetLayoutSections(string object_name, string layout_name){
|
List<String> componentNameList = new List<String>{object_name+'-'+layout_name};
|
//通过Metadata.Operations.retrieve获取metadata
|
//Metadata.Layout -> Metadata.LayoutSection -> Metadata.LayoutColumn objects -> Metadata.LayoutItem objects
|
List<Metadata.Metadata> componentList = Metadata.Operations.retrieve(Metadata.MetadataType.Layout, componentNameList);
|
if(componentList?.size() > 0){
|
Metadata.Layout layout = (Metadata.Layout) componentList.get(0);
|
List<Metadata.LayoutSection> layoutSectionList = layout.layoutSections;
|
return layoutSectionList;
|
}
|
else{
|
return null;
|
}
|
|
}
|
|
public static void Foo(){
|
string query = 'SELECT Layout.Name, Layout.TableEnumOrId, ProfileId, Profile.Name, RecordTypeId FROM ProfileLayout where recordtypeid=\'01210000000QfWdAAK\'';
|
|
String baseURL = URL.getSalesforceBaseUrl().toExternalForm()+'/services/data/v41.0/tooling/query?q='+ query.replace(' ', '+');
|
HttpResponse resp = null;
|
HttpRequest req = new HttpRequest();
|
req.setMethod('GET');
|
req.setHeader('Authorization', 'Bearer ' + UserInfo.getsessionid());
|
req.setEndpoint(baseURL);
|
Http client = new Http();
|
resp = client.send(req);
|
Map<string,object> mso = (Map<string,object>)JSON.deserializeUntyped(resp.getBody());
|
for(string key : mso.keySet()){
|
system.debug('key='+key);
|
system.debug(mso.get(key));
|
}
|
mso = (Map<string,object>)(((List<object>)mso.get('records'))[0]);
|
for(string key : mso.keySet()){
|
system.debug('key='+key);
|
system.debug(mso.get(key));
|
}
|
}
|
}
|