Skip to main content
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?
2 answers
  1. May 12, 2015, 2:50 PM
    Hi Daniel,

    try to check:

    - the field-level security on account field for opportunity object

    - eventually logics that could modify the Related_Billing_Contract__c value (e.g. workflows or triggers)

    - if the value of AccountId for "o" is what do you expect (system.assertEquals(a.Id,o.AccountId))

     
0/9000