0 votes
1 view
in Salesforce by (11.9k points)
edited by

Is there a way to increment a value in a map without needing a second variable?

for example, this doesn't work:

counts = new Map<string,integer>();

counts.put('month_total',0);

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

it returns "Initial term of field expression must be a concrete 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 increment without needing an extra variable?

1 Answer

0 votes
by (31.6k points)

For this, you'll have to replace

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

with

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

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...