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 ?

Adrian Larson
  • 149,971
  • 38
  • 239
  • 420
uma451
  • 141
  • 2
  • 4
  • 18
  • you can't use special character as variable name.. why you are using $ ? – Ratan Paul Feb 26 '16 at 05:58
  • I have generated apex class from JSON.In that structure there is a $ variable – uma451 Feb 26 '16 at 05:59
  • 1
    instead string take a map<String,String> this will solve your issue .. check this post I had same issue before http://salesforce.stackexchange.com/questions/100667/json-to-apex-conversion-with-number-variable-name – Ratan Paul Feb 26 '16 at 06:04

1 Answers1

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.

Adrian Larson
  • 149,971
  • 38
  • 239
  • 420
  • if the name contain $ symbol,then what will be the case ? – uma451 Feb 26 '16 at 06:02
  • @uma It makes the identifier invalid. Use only numbers, letters, and underscores./ – Adrian Larson Feb 26 '16 at 06: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 Feb 26 '16 at 06: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 Feb 26 '16 at 06:41