Salesforce通过Apex获取API名 Comparable排序

时间:2021-04-25 20:04:11

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>