public class SObjectSchema {

    public void testSchema(){
//获取SObject的token
//1、先获取所有token,然后通过key获取需要的token
//2、直接获取指定的sObject的token //1、通过获取全部描述信息,然后get方法获取需要的指定字段的描述信息
Map<String,Schema.SObjectType> allSObjectTypeDescribes = Schema.getGlobalDescribe();
Schema.SObjectType merchandiseType1 = allSObjectTypeDescribes.get('Merchandise__c'); //2、直接获取指定sObject的token
Schema.SObjectType merchandiseType2 = Merchandise__c.SObjectType; /*
* 获取Schema.DescribeSObjectResult
* 1、通过token的getDescribe方法**/
Schema.DescribeSObjectResult merchandiseResult = merchandiseType1.getDescribe(); /*
* 2、通过System命名空间下的Schema的方法
* */
List<String> sObjectTypes = new String[]{'Merchandise__c'};
List<Schema.DescribeSObjectResult> merchandiseResult1 = Schema.describeSObjects(sObjectTypes);
System.debug(merchandiseResult.getLabel());
System.debug('sObject的API的名称为' + merchandiseResult.getName());
System.debug('Student表是否为自定义的Object :' + (merchandiseResult.isCustom() ? '是':'否'));
//---------------------------------------//
List<Schema.ChildRelationship> childRelationResult = merchandiseResult.getChildRelationships();
for(Schema.ChildRelationship child : childRelationResult){
System.debug('merchandise子Object的关联名称:'+ child.getRelationshipName());
}
/**
* 以下操作位获取field的元信息结果,以Education__c为例
* 两种操作方式:
* 1、通过DescribeSObjectResult的fields方法获取token,然后再通过getDescribe方法获取
* 2、直接获取字段然后使用getDescribe方法
* */
Map<String,SObjectField> sObjectFieldMaps = merchandiseResult.fields.getMap();
SObjectField educationField = sObjectFieldMaps.get('Name');
Schema.DescribeFieldResult educationFieldResult = educationField.getDescribe();
Schema.DisplayType educationType = educationFieldResult.getType();
System.debug('education字段类型为:'+educationType);
System.debug('education字段API名称为:'+educationFieldResult.getName());
System.debug('education字段label名称为:'+educationFieldResult.getLabel());
//------------------------------//
List<Schema.PicklistEntry> educationListValues = educationFieldResult.getPicklistValues();
Map<String,Object> educationListValueMap = new Map<String,Object>();
for(Schema.PicklistEntry educationListItem : educationListValues){
educationListValueMap.put(educationListItem.getValue(),
new Map<String,Object>{
'value'=>educationListItem.getValue(),
'isActive'=>educationListItem.isActive(),
'isDefaultValue'=>educationListItem.isDefaultValue(),
'label'=>educationListItem.getLabel()
});
}
Set<String> educationListValuesSet = educationListValueMap.keySet();
System.debug('educations values'+educationListValuesSet); }
}

运行后的结果如下所示:

69、schema的相关方法的更多相关文章

  1. 69个经典Spring面试题和答案

    Spring 是个java企业级应用的开源开发框架.Spring主要用来开发Java应用,但是有些扩展是针对构建J2EE平台的web应用.Spring 框架目标是简化Java企业级应用开发,并通过PO ...

  2. 69道Spring面试题和答案

    1. 什么是spring? Spring 是个java企业级应用的开源开发框架.Spring主要用来开发Java应用,但是有些扩展是针对构建J2EE平台的web应用.Spring 框架目标是简化Jav ...

  3. 69道Java Spring 面试&笔试题

    目录 Spring 概述 依赖注入 Spring beans Spring注解 Spring数据访问 Spring面向切面编程(AOP) Spring MVC Spring 概述 1. 什么是spri ...

  4. 69道java Spring面试题和答案

    http://www.jfox.info/69-dao-java-spring-mian-shi-ti-he-da-an 目录 Spring 概述 依赖注入 Spring beans Spring注解 ...

  5. JAVA面试题:69道Spring面试题和答案

    目录 Spring 概述 依赖注入 Spring beans Spring注解 Spring数据访问 Spring面向切面编程(AOP) Spring MVC Spring 概述 1. 什么是spri ...

  6. 69个spring面试题及答案

    Spring 概述 1. 什么是spring? Spring 是个Java企业级应用的开源开发框架.Spring主要用来开发Java应用,但是有些扩展是针对构建J2EE平台的web应用.Spring ...

  7. 关于Spring的69个面试问答——终极列表

    本文由 ImportNew - 人晓 翻译自 javacodegeeks.欢迎加入翻译小组.转载请见文末要求. 这篇文章总结了一些关于Spring框架的重要问题,这些问题都是你在面试或笔试过程中可能会 ...

  8. [讨论] Window XP 安装msxml6后,load xml时提示schema验证失败

    现象:在windows XP x64下,使用用户安装的msxml6库加载xml文件时失败. 进一步说明: 该xml文档使用了W3C的名称空间 xmlns:xsi= "http://www.w ...

  9. 转载---关于Spring的69个面试问答

    链接:http://www.importnew.com/11657.html 目录 Spring概述 依赖注入 Spring Beans Spring注解 Spring的对象访问 Spring面向切面 ...

随机推荐

  1. ceph安装过程

    创建群集[2019-03-20 18:35:04,232][ceph_deploy.conf][DEBUG ] found configuration file at: /home/sceph/.ce ...

  2. Ionic4 入门

    1.搭建环境 1.电脑安装node.js,安装后电脑会自动安装npm     2.通过cmd命令,安装cnpm npm install -g cnpm -registry=https://regist ...

  3. xshell的安装及连接linux的使用方法

    版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/lx_Frolf/article/deta ...

  4. 斯坦福【概率与统计】课程笔记(五):EDA | 箱线图

    介绍箱线图之前,需要先介绍若干个其需要的术语 min:整个样本的最小值 max:整个样本的最大值 Range:即整个样本的取值范围,Range = max - min Inter-Quartile R ...

  5. appium报错及解决方案

    [已解决]mac上手动打开appium报错:“Could not find aapt Please set the ANDROID_HOME environment variable with the ...

  6. jsbridge 原理

    https://juejin.im/post/5abca877f265da238155b6bc

  7. 继承Process类,run函数的简单使用

    #定义一个类 继承Process类 from multiprocessing import Process import os import time class Download(Process): ...

  8. Java并发AtomicReference类

    java.util.concurrent.atomic.AtomicReference类提供了可以原子读取和写入的底层对象引用的操作,还包含高级原子操作. AtomicReference支持对底层对象 ...

  9. vue 中 element-ui 引入方式

    目录 前言 全部引用 单个引用 前言 有时候只会使用到 Element-ui 的部分功能,为了减少文件体积建议使用分开引用,即只引用使用的功能. 注意:在main.js中使用部分引用的时候是 impo ...

  10. 关于清除浮动的n中方式

    我们在对页面进行布局的时候经常会用到浮动布局,浮动布局能够很好的实现我们想要的布局效果,同时兼容方面也是很好的,但是当我们在用左右浮动进行页面布局的时候,由于元素浮动脱了了文档流导致浮动元素的父级高度 ...