1

I have this loop where I need to set a value inside a map (because VF is missing containsKey() function), but once the loop finishes, the value gets reset.

code

result

2

You're intentionally overwriting the value stored in your key again, so what I'd recommend is switching lines 166 and 167:

urlsh.put(p.Id, 'x');
for(Marketing_Comms__c cd: commDetails) {

This will place the default value only once in the map.

1

I believe the reason is there are more than one element in your commDetails. There is only one element which satisfies the if statement. But there are more yet to come. The last element doesn't satisfy the if statement and changed the value of p.id key back into 'x'.

In order to prove this, you can put a System.debug(urlsh) at the end of for loop which is inside the for loop but outside the if statement. You will see the proof.

  • Yes, that was it. Very subtle! – dzh Oct 18 '16 at 0:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.