I am compile error as in subject line for below code. Can someone please help me?

Apex Code Snippet

     answerchoices.put(sq.Text_vod__c,new Map<Integer, String[]>{cd[iterator],cd[iterator+2]};
  • in map we need assgin like {key => value, key => value} like this
    – Ratan Paul
    May 12 '16 at 9:38
  • what is cd a collection of, and how can you be sure that cd[i] is an integer and cd[i+2] is a String array?
    – Doug B
    May 12 '16 at 9:42

Try to change your code to

Map<Integer, List<String>> copyMap = new Map<Integer, List<String>>();
for(iterator=0; iterator<(cd.size()/2); iterator++)
   //copyMap = new Map<Integer, String[]>();
      copyMap.put(cd[iterator], new Map<Integer, List<String>>());

This my help you out.

  • It is fine but only problem is that I wrote the syntax wrong. Can you please let me know how to put multiple strings in the above String[]? May 12 '16 at 9:57
  • Have updated my answer. Hope you where looking for this.
    – Anu
    May 12 '16 at 10:04
  • No What I meant was, copy map will have values like ('1',('X','Z')). Now iterator stands for '1' and cd[iterator] = X, cd[iterator+2] =Z. So how to put X, Z in place of that string[].? Key value in copymap would be iterator only. May 12 '16 at 10:09
  • Yes I got it try with the updated code.
    – Anu
    May 12 '16 at 10:10
  • I am sorry I am unable to brief the case properly I guess. in copymap I need to put three values. First One the integer i.e. iterator, Second and third one two string values - cd[iterator],cd[iterator+2]. These two string values will be put to String[] part. May 12 '16 at 10:15

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.