function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mike_M_2Mike_M_2 

Variable userInfo is used before it is declared

this error: 

Error

Error: Compile Error: Variable userInfo is used before it is declared. at line 62 column 42

 

on the following line

 

string platformUsername =
[select Platform_Username__c from User where id = :UserInfo.getUserId()].Platform_Username__c;

 

Do I have to declare UserInfo?  If so, how?

 

Thanks,

Mike

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Anup JadhavAnup Jadhav

No, just remove the : in front of UserInfo and you should be fine.

 

So, rewrite it as:

 

string platformUsername = [select Platform_Username__c from User where id = UserInfo.getUserId()].Platform_Username__c;

 Hope this helps!

All Answers

Anup JadhavAnup Jadhav

No, just remove the : in front of UserInfo and you should be fine.

 

So, rewrite it as:

 

string platformUsername = [select Platform_Username__c from User where id = UserInfo.getUserId()].Platform_Username__c;

 Hope this helps!

This was selected as the best answer
tsritsri
Having Similar issue..

even when I remove : in front of UserInfo.. its giving some other error as "unexpected token: 'Userinfo'"