如何在SF中按字母顺序获取字段列表 [英] How do i get a list of fields in alphabetical order in SF

查看:78
本文介绍了如何在SF中按字母顺序获取字段列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将对象中的所有字段按字母顺序排列.我尝试使用apex资源管理器来获取字段,尽管大多数字段按顺序排列,但很少有字段按不正确的顺序排列.

I am trying to get all the fields in an object to comeup in a alphabetical order. i have tried using apex explorer to get the fields, though most of the fields come up in an order, there are few fields which do not come up in the right order.

以特定顺序获取字段名称可能不会影响代码的工作,但是作为我们项目中使用的标准的一部分,希望我们按字母顺序使用它们.

Getting the field names in a particular order might not affect the code working, but as a part of standards used in our project, it is expected that we use them in alphabetical order.

谢谢 普拉迪

推荐答案

此食谱有效:

List<Contact> contacts = [SELECT Name, Id FROM Contact ORDER BY Id LIMIT 10]; // We'll reorder by Name later
Map<String, Contact> contactMap = new Map<String, Contact>(); // Reversed for sorting
List<String> sortThis = new List<String>();

for(Contact c : contacts)
{
   contactMap.put(c.Name, c); // For simplicity in this example, we assume the name is unique
   sortThis.add(c.Name);
}

sortThis.sort(); // Sort by Name in this case    
List<Contact> nameSortedContacts = new List<Contact>();

for(String s : sortThis)
{
   nameSortedContacts.add(contactMap.get(s));
}

我还没有测试过,但是看起来很准确.

I haven't tested this but it looks accurate.

这篇关于如何在SF中按字母顺序获取字段列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆