How to increase the value on the map using Apex?

Is there a way to increase the value on the map without requiring a second variable?

for example, this does not work:

counts = new Map<string,integer>(); counts.put('month_total',0); counts.put('month_total',counts.get['month_total']++); 

it returns "The initial term of the field expression must be a specific SObject: MAP"

instead, I needed to do:

 counts = new Map<string,integer>(); counts.put('month_total',0); integer temp = 0; temp++; counts.put('month_total',temp); 

Is there any way to increase without requiring an extra variable?

+4
source share
1 answer

Replace

 counts.put('month_total',counts.get['month_total']++); 

with

 counts.put('month_total',counts.get('month_total')++); 
+4
source

Source: https://habr.com/ru/post/1490824/


All Articles