salesforce 得到下拉列表控制依赖值的方法
salesforce中得到下拉列表的控制依赖值没有系统提供的方法。在网上找了一些,自己也编辑了一下。
public static List<Integer> B64ToBytes (String sIn) {
Map<Integer,Integer> base64 = new Map<Integer,Integer>{65=>0,66=>1,67=>2,68=>3,69=>4,70=>5,71=>6,72=>7,73=>8,74=>9,75=>10,76=>11,77=>12,78=>13,79=>14,80=>15,81=>16,82=>17,83=>18,84=>19,85=>20,86=>21,87=>22,88=>23,89=>24,90=>25
,97=>26,98=>27,99=>28,100=>29,101=>30,102=>31,103=>32,104=>33,105=>34,106=>35,107=>36,108=>37,109=>38,110=>39,111=>40,112=>41,113=>42,114=>43,115=>44,116=>45,117=>46,118=>47,119=>48,120=>49,121=>50,122=>51
,48=>52,49=>53,50=>54,51=>55,52=>56,53=>57,54=>58,55=>59,56=>60,57=>61,43=>62,47=>63};
List<Integer> lstOut = new List<Integer>();
if ( sIn == null || sIn == '' ) return lstOut;
sIn += '='.repeat( 4 - Math.mod( sIn.length(), 4) );
for ( Integer idx=0; idx < sIn.length(); idx += 4 ) {
if ( base64.get(sIn.charAt(idx+1)) != null ) lstOut.add( (base64.get(sIn.charAt(idx)) << 2) | (base64.get(sIn.charAt(idx+1)) >>> 4) );
if ( base64.get(sIn.charAt(idx+2)) != null ) lstOut.add( ((base64.get(sIn.charAt(idx+1)) & 15)<<4) | (base64.get(sIn.charAt(idx+2)) >>> 2) );
if ( base64.get(sIn.charAt(idx+3)) != null ) lstOut.add( ((base64.get(sIn.charAt(idx+2)) & 3)<<6) | base64.get(sIn.charAt(idx+3)) );
}
//System.Debug('B64ToBytes: [' + sIn + '] = ' + lstOut);
return lstOut;
}//B64ToBytes
public static List<Integer> BlobToBytes (Blob input) {
return B64ToBytes( EncodingUtil.base64Encode(input) );
}//BlobToBytes
// Converts a base64 string into a list of integers indicating at which position the bits are on
public static List<Integer> cnvBits (String b64Str) {
List<Integer> lstOut = new List<Integer>();
if ( b64Str == null || b64Str == '' ) return lstOut;
List<Integer> lstBytes = B64ToBytes(b64Str);
Integer i, b, v;
for ( i = 0; i < lstBytes.size(); i++ ) {
v = lstBytes[i];
//System.debug ( 'i['+i+'] v['+v+']' );
for ( b = 1; b <= 8; b++ ) {
//System.debug ( 'i['+i+'] b['+b+'] v['+v+'] = ['+(v & 128)+']' );
if ( ( v & 128 ) == 128 ) lstOut.add( (i*8) + b );
v <<= 1;
}
}
//System.Debug('cnvBits: [' + b64Str + '] = ' + lstOut);
return lstOut;
}//cnvBits
public class TPicklistEntry{
public string active {get;set;}
public string defaultValue {get;set;}
public string label {get;set;}
public string value {get;set;}
public string validFor {get;set;}
public TPicklistEntry(){
}
}//TPicklistEntry
//得到控制字段对应的依赖字段值的集合
public static Map<String,Set<String>> getDependentOptions(String pObjName, String pControllingFieldName, String pDependentFieldName) {
Map<String,Set<String>> mapResults = new Map<String,Set<String>>();
//verify/get object schema
Schema.SObjectType pType = Schema.getGlobalDescribe().get(pObjName);
if ( pType == null ) return mapResults;
Map<String, Schema.SObjectField> objFieldMap = pType.getDescribe().fields.getMap();
//verify field names
if (!objFieldMap.containsKey(pControllingFieldName) || !objFieldMap.containsKey(pDependentFieldName)) return mapResults;
//get the control & dependent values
List<Schema.PicklistEntry> ctrl_ple = objFieldMap.get(pControllingFieldName).getDescribe().getPicklistValues();
List<Schema.PicklistEntry> dep_ple = objFieldMap.get(pDependentFieldName).getDescribe().getPicklistValues();
//clear heap
objFieldMap = null;
//initialize results mapping
for(Integer pControllingIndex=0; pControllingIndex<ctrl_ple.size(); pControllingIndex++){
mapResults.put( ctrl_ple[pControllingIndex].getValue(), new Set<String>());
}
//cater for null and empty
mapResults.put('', new Set<String>());
mapResults.put(null, new Set<String>());
//serialize dep entries
List<TPicklistEntry> objDS_Entries = new List<TPicklistEntry>();
objDS_Entries = (List<TPicklistEntry>)JSON.deserialize(JSON.serialize(dep_ple), List<TPicklistEntry>.class);
List<Integer> validIndexes;
for (TPicklistEntry objDepPLE : objDS_Entries){
validIndexes = cnvBits(objDepPLE.validFor);
//System.Debug('cnvBits: [' + objDepPLE.label + '] = ' + validIndexes);
for (Integer validIndex : validIndexes){
mapResults.get( ctrl_ple[validIndex-1].getValue() ).add( objDepPLE.value );
}
}
//clear heap
objDS_Entries = null;
return mapResults;
}//GetDependentOptions
//通过依赖值找到它对应的控制值
public static String getControllingValue(String pObjName, String pControllingFieldName, String pDependentFieldName, String pDependentValue)
{
String controllingValue = null;
//verify/get object schema
Schema.SObjectType pType = Schema.getGlobalDescribe().get(pObjName);
if ( pType == null ) return controllingValue;
Map<String, Schema.SObjectField> objFieldMap = pType.getDescribe().fields.getMap();
//verify field names
if (!objFieldMap.containsKey(pControllingFieldName) || !objFieldMap.containsKey(pDependentFieldName)) return controllingValue;
//get the control & dependent values
List<Schema.PicklistEntry> ctrl_ple = objFieldMap.get(pControllingFieldName).getDescribe().getPicklistValues();
List<Schema.PicklistEntry> dep_ple = objFieldMap.get(pDependentFieldName).getDescribe().getPicklistValues();
//clear heap
objFieldMap = null;
//serialize dep entries
List<TPicklistEntry> objDS_Entries = new List<TPicklistEntry>();
objDS_Entries = (List<TPicklistEntry>)JSON.deserialize(JSON.serialize(dep_ple), List<TPicklistEntry>.class);
List<Integer> validIndexes;
for (TPicklistEntry objDepPLE : objDS_Entries){
if (objDepPLE.label == pDependentValue)
{
validIndexes = cnvBits(objDepPLE.validFor);
System.debug('validIndexes:::' + validIndexes);
if (validIndexes.size()>0) {
controllingValue = ctrl_ple[validIndexes.get(0) - 1].getLabel();
}
}
if (objDepPLE.value == pDependentValue)
{
validIndexes = cnvBits(objDepPLE.validFor);
System.debug('validIndexes:::' + validIndexes);
if (validIndexes.size()>0) {
controllingValue = ctrl_ple[validIndexes.get(0) - 1].getValue();
}
}
}
objDS_Entries = null;
return controllingValue;
}
salesforce 得到下拉列表控制依赖值的方法的更多相关文章
- jquery获取下拉列表的值和显示内容的方法
页面的下拉列表: 选择时间段: <select name="timespan" id="timespan" class="Wdate" ...
- layui利用jQuery设置下拉列表的值
今天在利用jQuery动态设置下拉列表的值的时候确怎么也赋值不上去,其中用到了layui框架,源代码如下: $.post(contextPath+'/courseLibrary/getCourseBa ...
- jQuery中设置form表单中action的值的方法
下面介绍在jQuery中设置form表单中action的值的方法. $("#myFormId").attr("action", "userinfo.s ...
- js 判断数组包含某值的方法 和 javascript数组扩展indexOf()方法
var questionId = []; var anSwerIdValue = []; ////javascript数组扩展indexOf()方法 Array.prototype.indexOf ...
- PHP获取MySql新增记录ID值的方法
今天发现用mysql_insert_id()获取到的新增记录的id不正确, 虽然发现源代码的事务写的有问题,但是最根本的原因是,我插入数据的id类型是bigint型 获取MySql新增记录ID值的方法 ...
- MySQL设置当前时间为默认值的方法
方法一.是用alert table语句: 复制代码代码如下: use test_db1; create table test_ta1( id mediumint(8) unsigned not nul ...
- jquery通过name属性取值的方法
jquery通过name属性取值的方法//$("input[name='imgtitle']").val();//这个只能取到第一个的值//通过each函数取得所有input的值v ...
- jquery得到iframe src属性值的方法
这篇文章主要介绍了jquery得到iframe src属性值的方法,很简单,很实用,需要的朋友可以参考下 取得iframe src属性的的值: Html代码 <!DOCTYPE HTML> ...
- C#中使用MySqlCommand执行插入语句后获取该数据主键id值的方法
.net中要连接mysql数据库,需要引用MySql.Data.dll文件,这文件在mysql官网上有下载. 接着通过MySqlCommand执行插入语句后想要获取该数据主键id值的方法如下: lon ...
随机推荐
- Texlive + TexStudio + Language Tool Win7配置
Texlive的配置很简单,安装的时候跟着向导一步一步安装就可以了. TexStudio也是同样的安装过程,没什么技巧.这里提一下界面颜色的配置.习惯了暗底白字,所以就google了一下相关的配置,大 ...
- Python系列教程(三):输入和输出
1.1 raw_input() 在Python中,获取键盘输入的数据的方法是采用 raw_input 函数(至于什么是函数,咱们以后的章节中讲解),那么这个 raw_input 怎么用呢? 看如下示例 ...
- Educational Codeforces Round 20.C
C. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- spring +springmvc+mybatis组合applicationContext.xml文件配置
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...
- 新闻信息的javaBean
//新闻信息的javaBeanpublic class News { //新闻属性 private int id; //id private int categoryId ;//新闻类别id priv ...
- Spring+Mybatis配置
Spring+Mybatis配置 之前做项目的时候用到了spring+mybatis框架,一直想抽空整理一下 Mybatis: mybatis是支持普通 SQL查询,存储过程和高级映射的优秀持久层框架 ...
- Java自学手记——集合
- voa 2015 / 4 / 19
potentially – adv. capable of becoming real, a possibility tackle – v. to deal with a difficult pr ...
- Debian 8添加kali更新源并安装metasploit
一.Debian 8添加kali更新源 中科大kali更新源: deb http://mirrors.ustc.edu.cn/kali kali-rolling main non-free contr ...
- CSS 选择器优先级问题
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> &l ...