![](/img/trans.png)
[英]Display <apex:inputField values> based on the value of the first input Field salesforce
[英]How to display Map's list value based on 1 key in Apex Salesforce?
你好美麗的人,
我有一個場景,我正在使用字符串鍵和列表定義 Map。 現在,我想將值一個一個地放入列表中,並使用單個鍵顯示它們。 示例代碼 -
Map<string,List<Account>> accountMap = new Map<string,List<Account>>();
//How to insert values. I am using this but no luck-
for(Account acc = [Select Id, Name from Account]){
accountMap(acc.Id,accList)
}
//Lets say we have data. How to display any **specific** value from the middle of the list. I am using this but no luck-
AccountList.get(id).get(3);
請幫忙。
以帳戶 ID 為例是個糟糕的主意,因為它們將是唯一的 -> 您的列表的大小始終為 0。但是,是的,您應該能夠做類似的事情。
你的東西甚至不能編譯,你不能在for(Account acc = [SELECT...])
中使用“=”。
假設您有帳戶,其中一些帳戶有重名。 這將接近您的需要:
Map<string,List<Account>> accountMap = new Map<string,List<Account>>();
for(Account acc : [SELECT Name, Description FROM Account LIMIT 100]){
if(accountMap.containsKey(acc.Name)){
accountMap.get(acc.Name).add(acc);
} else {
accountMap.put(acc.Id, new List<Account>{acc});
}
}
然后是的,如果您有密鑰,您可以訪問accountMap.get('Acme Inc.')[0].Id
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.