I am trying to create a test class, and I'm using this function to generate data. It creates the account properly, and my system debug shows that I am successfully querying and returning values with toRef. BUt then when I try to assign the returned id to nd1.Account__c it tosses the title error.
As far as I can tell, nothing should be wrong with the code. Can anyone explain why it's not working? Thanks!
public static void genData()
{
System.debug('Generating Data...::');
Account ac = new Account();
VS_Design__c nd1, nd2 = new VS_Design__c();
ac.Name = 'Test Account';
insert ac;
System.debug('Account Inserted.. ::');
Account toRef = [SELECT Id, Name
FROM Account
WHERE Name = 'Test Account'
LIMIT 1];
System.debug('toRef Results :: ' + toRef.Id + ' ' + toRef.Name); //this returns the ID and Name properly
//Design Insertion 1
nd1.Account__c= toRef.Id; \\error happens here
nd1.Status__c = 'Closed';
nd1.Approved_By__c = toRef.Id;
nd1.Approved_On__c = Date.today();
insert nd1;
//Design Insertion 2
nd2.Account__c = toRef.Id;
nd2.Status__c = 'New';
insert nd2;
//Update Design 2 to run Trigger, then run test
nd2.Status__c = 'Closed';
nd2.Approved_By__c = toRef.Id;
nd2.Approved_On__c = Date.today();
update nd2;
}
ac.ID
should be fine