[Salesforce]Get Object API reference name and Prefix from object label

    String searchObjLabelName = '取引先企業';
	String targetObjectName = '';

    Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
    for (String sKey : gd.keySet()) {
        Schema.DescribeSObjectResult targetObject = gd.get(sKey).getDescribe();
        if(targetObject.getLabel() == searchObjLabelName){
            targetObjectName = targetObject.getName();
			System.debug('targetObject.getLabel()----->targetObject.getName()::::::'+targetObject.getLabel()+'----->'+targetObject.getName());
        }
    }

    String objName = targetObjectName;	
    schema.sObjectType sObjType = Schema.getGlobalDescribe().get(objName);
    system.debug('prefix:'+(sObjType.getDescribe().getKeyPrefix()));

投稿者: kinkun

保有資格 Salesforce Certified Platform App Builder T Salesforce Certified Platform Developer I Salesforce Certified Platform Developer II Salesforce Certified Administrator

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です