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
acousticacoustic 

Access an Account Id in test class

Here is the beginning of my test class wehre I'm setting up test records. I'm getting an error: "Error: Compile Error: unexpected token: 'Acct.ID' at line 11 column 107" 

 

Later in the code I can easily access User fields (U.id for example). Why can't I access Acct.Id? Is it because it is in SOQL statement?  Thanks!

 

//set up records
User U = [select id from USer limit 1];

//setup Account record 
Account Acct = ([select id, type__c from Account limit 1]);

Acct_Plan__c ap = ([select Id, Name, Account__c, Planning_Year__c from Acct_Plan__c where Account__c = Acct.Id]);

 

Best Answer chosen by Admin (Salesforce Developers) 
MktdevMktdev

Since you are trying to access existing org data so try using before test method or test class

 

@isTest(SeeAllData=true)

All Answers

MktdevMktdev

Since you are trying to access existing org data so try using before test method or test class

 

@isTest(SeeAllData=true)
This was selected as the best answer
acousticacoustic
Thanks a lot!!