无时无刻不处在一个于Fields打交道的时候。
- 获取FiledMap
public static Map<string,string> fetchFieldMap(string objName) {
Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
Map <String, Schema.SObjectField> fieldMap = schemaMap.get(objName).getDescribe().fields.getMap();
Map<String,string> labelFieldMap = new Map<string,string>();
for (String fieldName: fieldMap.keySet()) {
labelFieldMap.put(fieldMap.get(fieldName).getDescribe().getLabel(),fieldMap.get(fieldName).getDescribe().getName());
}
return labelFieldMap;
}
结果如下:
{AUM=FinServ__AUM__c, Account Description=Description, Account Fax=Fax, Account Health=PwC_Account_Health__c, Account ID=Id, Account Name=Name, Account Number=AccountNumber, Account Phone=Phone, Account Quality=PwC_Account_Quality__c, Account Rating=Rating, ...}
- 获取Field Set
Field set是一组field的集合。当一个 field set加入VF page的时候,开发可以循环遍历渲染它。当这个页面加到了managed package,系统管理员可以添加,移除和重新排列这些字段用来在页面展示。
List<Schema.FieldSetMember> FieldSetMemberList = SObjectType.Account.FieldSets.PwC_Account_Score_Rule_Field_Set.getFields();
String selects = '';
for(Schema.FieldSetMember f : FieldSetMemberList)
{
selects += f.getFieldPath() + ', ';
}
结果是:
Account_Score__c,
Completed_Tasks_In_Last_60_Days__c,
NumberOfEmployees,
Task_Count_Total__c,
AnnualRevenue,
Score_Rule__c,
Closed_Won_Opps_In_Last_6_Months__c,
网友评论