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. Java牛角尖【007】:Java中的Error能不能被Catch

      Java牛角尖[007]:Java中的Error能不能被Catch 网上看到很多朋友说Java中Error是无法Catch到的,而Java中定义的Error类型又很难测试到,那就估且以为确是如此吧 ...

  2. 【玩转SpringBoot】异步任务执行与其线程池配置

    同步代码写起来简单,但就是怕遇到耗时操作,会影响效率和吞吐量. 此时异步代码才是王者,但涉及多线程和线程池,以及异步结果的获取,写起来颇为麻烦. 不过在遇到SpringBoot异步任务时,这个问题就不 ...

  3. JMeter的那些问题

    我们从以下几个点来看jmeter: 1.jmeter是什么? 2.jmeter为什么我们要使用jmeter?他可以帮我们解决那些事情? 3.怎样使用jmeter做这些事情? 4.我们在什么时候会使用j ...

  4. javaIO流(五)--对象序列化

    一.序列化概念 几乎只要是我们的java开发,就一定会存在有序列化的概念,而正是有序列化的概念逐步发展,慢慢也有了更多的系列化的标准.--所谓的对象序列化指的是将内存中保存的对象,以二进制数据流的形式 ...

  5. run (简单DP)

    链接:https://www.nowcoder.com/acm/contest/140/A 来源:牛客网 题目描述 White Cloud is exercising in the playgroun ...

  6. java并发编程之美-阅读记录7

    java并发包中的并发队列 7.1ConcurrentLinkedQueue 线程安全的无界非阻塞队列(非阻塞队列使用CAS非阻塞算法实现),其底层数组使用单向列表实现,对于出队和入队操作使用CAS非 ...

  7. 后台得到jsp提交name属性相同的内容

    直接上代码: req.setCharacterEncoding("utf-8");String [] node = req.getParameterValues("nod ...

  8. DB2实例

    实例是逻辑数据库管理环境,可以在此环境中对数据库进行编目和设置配置参数.根据需要, 可以在一台服务器上创建多个实例,该服务器为每个实例提供唯一的数据库服务器环境.   默认实例:DB2   显示实例: ...

  9. Robot Framework使用技巧之内部变量

    [转载] 1.变量的使用 变量可以在命令行中设置,个别变量设置使用--variable (-v)选项,变量文件的选择使用--variablefile (-V)选项. 通过命令行设置的变量是全局变量,对 ...

  10. @HttpEntity参数(怪异)

    1).在Controller中写 与@RequestBody请求体对应 @HttpEntity更强大,不光有请求体,还能获取请求头 @RequestMapping("/test02" ...