• Daniel Marcus
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
Hi All,

I'm getting a null value on a lookup field when running a test class.
 
Account a = new Account(Name = '1', Owner = u, CurrencyIsoCode = 'CAD');
        insert a;
		a = [SELECT id, AccountNumber, Name, CurrencyIsoCode, Related_Billing_Contract__c FROM account WHERE id = :a.id];

		Billing_Contract__c bc = new Billing_Contract__c(Account__c = a.id, Active__c = TRUE, Annual_Increase_Amount__c = 0.03, Billing_Frequency__c = 'Annually');
		insert bc;
		bc = [SELECT id FROM Billing_Contract__c WHERE id = :bc.id];

		a.Related_Billing_Contract__c = bc.id;
		update a;

		a = [SELECT id, AccountNumber, Name, CurrencyIsoCode, Related_Billing_Contract__c FROM account WHERE id = :a.id];

		System.debug('Related_Billing_Contract__c: ' + a.Related_Billing_Contract__c);
        
        Opportunity o = new Opportunity(Name = '2', GSS_Rep__c = g.id, Account = a, StageName = 'No Status', CloseDate = System.today(), Amount = 1, Type = 'New Implementation', License_Model__c = 'Perpetual', Owner = u, Sales_Rep2__c = s.id, Pricebook2Id = p.id, CurrencyIsoCode = 'CAD', Intall_Date_Opp__c = system.today(), Milestone_Trigger__c = 'Installation', Payment_Terms_Drop__c = '30 Days on Order');
        insert o;

        o = [SELECT id, AccountId, Account.AccountNumber, Account.Related_Billing_Contract__c, Account.Name, Name, Service_Value_No_Milesotne__c, CurrencyIsoCode, Software_Value_No_Milestone__c, Account.Id, Account.Licensing_Model__c, type, Service_Days__c FROM opportunity WHERE id = :o.id];

        System.debug('o.account.Related_Billing_Contract__c: ' + o.Account.Related_Billing_Contract__c);

My initial Debug returns an ID for the Account.Related_Billing_Contract__c, but when I go through the Opportunity to find the same value (Opportunity.Account.Related_Billing_Contract__c) I am getting NULL returned. Any help?