Salesforce通过Apex获取API名 Comparable排序

apex

public with sharing class Apiget {
    //表示用リストクラス
	 public List<apiname> apinameList{get;set;} 
	 public list<IComparable> iComparaList{get;set;} 
	 
	 public with sharing class apiname {
	      //データ格納用クラス
		 public String objectLabel{get;set;}
		 public String objectName{get;set;}
		 public String objectkeyPrefix{get;set;}
		 public boolean custom{get;set;}
	}
	 
	 //コンストラクタ
	 public void Apiget(){
	 
		 //全オブジェクト情報取得
		 MAP<string,Schema.SObjectType> sobMap =schema.getGlobalDescribe();
		 apinameList = new List<apiname>();
		 iComparaList = new list<IComparable>();
		 for(String sobStr : sobMap.keySet()){
			 apiname apnameclass = new apiname();
			 Schema.SObjectType sobType = sobMap.get(sobStr);
			 Schema.DescribeSObjectResult sobRes = sobType.getDescribe();		
			 apnameclass.objectLabel = sobRes.label;
			 apnameclass.objectName = sobRes.name;
			 apnameclass.objectkeyPrefix = sobRes.keyPrefix;
			 apnameclass.custom = sobRes.custom;
			 iComparaList.add(new IComparable(apnameclass));
		 }
		 iComparaList.sort();
	 }
	 
	 // ソート
	 public class IComparable implements Comparable {
    	public apiname oppy{get;set;}

	    public IComparable(apiname op) {
	        oppy = op;
	    }
	    
	    public Integer compareTo(Object compareTo) {
	        // Cast argument to OpportunityWrapper
	        IComparable compareToOppy = (IComparable)compareTo;
	        Integer returnValue = 0;
	        if (oppy.custom ) {
	            returnValue = 0;
	        } else if (!oppy.custom) {
	            returnValue = 1;
	        }
	        
	        return returnValue;       
	    }
	}
}

VisualForce

<apex:page controller="Apiget" action="{!Apiget}" >
<apex:form id="frm">
   <apex:pageBlock > 
		<apex:pageBlockTable value="{!iComparaList}" var="item" id="theRepeat">          
	       		<apex:column value="{!item.oppy.custom}">
	       			<apex:facet name="header">
			                 カスタム区分
			         </apex:facet>
			    </apex:column>
	       		<apex:column value="{!item.oppy.objectLabel}">
	       			<apex:facet name="header">
			                           ラベル名
			         </apex:facet>
			    </apex:column>
				<apex:column value="{!item.oppy.objectName}">
					<apex:facet name="header">
			            API名
			         </apex:facet>
			    </apex:column>
				<apex:column value="{!item.oppy.objectkeyPrefix}">
					<apex:facet name="header">
			             ID
			         </apex:facet>
			    </apex:column>
        </apex:pageBlockTable>   
        </apex:pageBlock>   
    </apex:form>
</apex:page>


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值