0

I have written apex class.variable declaration is:

public string QPA$MV2 {get;set;}

It shows error:

Error: Compile Error: Invalid identifier: QPA$MV2 at line 254 column 23 How to resolve it ?

3
  • you can't use special character as variable name.. why you are using $ ?
    – Ratan Paul
    Commented Feb 26, 2016 at 5:58
  • I have generated apex class from JSON.In that structure there is a $ variable
    – uma451
    Commented Feb 26, 2016 at 5:59
  • 1
    instead string take a map<String,String> this will solve your issue .. check this post I had same issue before salesforce.stackexchange.com/questions/100667/…
    – Ratan Paul
    Commented Feb 26, 2016 at 6:04

1 Answer 1

1

All class/property/method identifiers must be alphanumeric and cannot contain the underscore (_) character twice in a row. At least for class, you can find a good description of the rules:

The name can only contain characters, letters, and the underscore (_) character, must start with a letter, and cannot end with an underscore or contain two consecutive underscore characters.

I think by characters, letters, and the underscore (_) character, they meant numbers, letters, and the underscore (_) character.

Your original post made no mention of JSON, but you can find solutions to that problem here.

4
  • if the name contain $ symbol,then what will be the case ?
    – uma451
    Commented Feb 26, 2016 at 6:02
  • @uma It makes the identifier invalid. Use only numbers, letters, and underscores./
    – Adrian Larson
    Commented Feb 26, 2016 at 6:03
  • I have generated a class from JSon.Usion JSON to Apex converter I generated the class.it gives the variable as "public double QPA$MV2 {get;set;}" while saving it shows error.
    – uma451
    Commented Feb 26, 2016 at 6:04
  • @uma - See the link Adrian included. Apex names cannot have $. If the Json2Apex generator gave you invalid variable names, change them to valid ones and use the techniques in the link to fix up the json before you deserialize
    – cropredy
    Commented Feb 26, 2016 at 6:41

Not the answer you're looking for? Browse other questions tagged .