0

I've a multi-select pick list that has initials in a specific order (not alphabetical), those initials are for team ranking purposes. so every time i add a member to the team, he must be saved and displayed on the report according to his ranking (initials).

for instance, if my rankings are: AB, XY, FC, and DQ, and then i created two members (FC, AB), the one with AB MUST be displayed on the report before FC.

I've created a list that has the initials in the desired order, and every time a member is created it's being added to a different list. what I'm getting now is, the last member created (last member added to the list) is displayed at the end of the report, even if his ranking is higher than those were added before him. so my question is: How do i save the members that I add to the list according to my rankings order?

Thank you guys for your efforts!

4

2 回答 2

0

据我所知,您只能使用将新项目放在列表末尾的 add 或 addAll 函数将项目添加到列表中。您也可以使用数字索引替换项目,但这不会提供您似乎所指的插入功能。但是,您可以添加新的列表成员,然后调用列表上的排序函数以升序对事物进行排序。这将给出您所追求的结果。这是一个例子:

List<String> rankings = new List<String>();
rankings.add('XY');
rankings.add('AB');
rankings.add('FC');  // you should now have ['XY', 'AB', 'FC']
rankings.sort();     // should rearrange the list items to be ['AB', 'FC', 'XY']

更多信息: http: //www.salesforce.com/us/developer/docs/apexcode/Content/apex_System_List_sort.htm

但是,这只会给您留下一个排序的字符串列表,并且没有指向关联记录的链接。如果您要在控制器中或通过 ajax 添加记录,那么您也可以对成员运行 soql 查询并按您的排名字段排序,以获得一个应用了您的排序的新列表。在没有看到您的实现或不知道您正在做什么的任何细节的情况下,很难说最好的方法是什么,但正如我在上面所展示的,即使在添加列表对象之后也可以保持对其进行排序。

于 2013-11-26T15:06:07.503 回答
0

为什么你有一个多选的排名选项列表?每个成员只有一个排名,对吗?如果是这种情况,标准的选择列表应该可以解决问题。

您应该为尝试创建列表的组成员创建 SOQL 查询,然后使用 Order By 子句按选项列表字段值排序。

IE

假设:

对象 - 用户

Ranking Picklist field -ranking__c //用户对象上包含排名的自定义字段,

Team - team__c //用户对象上的自定义字段,包含成员的团队编号。

列出用户 = new List();

users = [SELECT ID from user where ranking_c != NULL AND Team _c = 'Some Value' ORDER BYranking__c];

//其他一些代码对排序的用户列表做一些事情。请注意 order by 子句按自定义“ranking__c”字段中的值排序。

希望这个对你有帮助。

问候,J

于 2013-12-05T18:41:20.067 回答