5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Apex Mapクラスの初期化

Posted at

1,2は別にあえて書くまでもないけど、3,4あたりはたまに忘れてるので、まとめてみた。

1.Map<T1, T2>()

普通の使い方

2.Map(mapToCopy)

他のマップをコピー
(動き的にはMap<T1,T2> hoge = mapToCopy.clone()と同じっぽい)

3.Map(recordList)

sObjectのリストだけで使える特殊パターン
そのsObjectのIDをキーにしたMAPを作ってくれる
使い方は以下のような感じ

Map<ID, Account> = new Map<Id, Account>([SELECT ID, Name FROM Account]);

4.Map{T1 => T2(, T1 => T2 ...)}

値を入れて初期化したい場合

使い方は以下のような感じ

Map<ID, String> zionMS= new Map<Id, String>{
    'EMS-04' => 'ヅダ'
    , 'MS-04' => 'プロトタイプザク'
    , 'MS-05' => 'ザクI'
    , 'MS-06' => 'ザクII'
    , 'MS-07' => 'グフ'
    , 'MS-08' => 'イフリート'
    , 'MS-09' => 'ドム'
    , 'EMS-10' => 'ヅダ'
    , 'MS-10' => 'ドワッジ'
    , 'MS-11' => 'アクトザク'
    , 'MS-12' => 'ギガン'
    , 'MS-13' => 'ガッシャ'
    , 'MS-14' => 'ゲルググ'
    , 'MS-15' => 'ギャン'
}
5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?