Quantcast
Channel: How to initialize List/Set values by construction in apex? - Salesforce Stack Exchange
Viewing all articles
Browse latest Browse all 3

How to initialize List/Set values by construction in apex?

$
0
0

I have different object snippet at many places (shown below) and I want below 4 lines to be converted into a single line. How we can do it in Apex ?

Map<String, List<Configuration__c>> mapConfig = new Map<String, List<Configuration__c>>();
Configuration__c c = // detail coming from DB here
List<Configuration__c> tempList = serviceTypeFieldsMap.get(detail.ServiceType__c);
tempList.add(c);
mapConfig.put(detail.ServiceType__c, tempList);

I tried many things, but did not worked out.

mapConfig.put(detail.ServiceType__c, serviceTypeFieldsMap.get(detail.ServiceType__c).add(c));

Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images