Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
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 (32.1k 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')++);

Browse Categories

...