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
kumar palepukumar palepu 

showing null value for afiled when execute in test class for Trigger.

In below code showing site value is null in debug.kindly help us to resolve the issue.
@isTest
public class testOnUpdation{
static testmethod void Siteupdate()
{
Account aa = new Account (name='istest',RecordTypeId='012j0000000ogEQAAY',Site='istest');
insert aa;
System.Test.startTest();
system.debug('starttest');
Account bb= new Account(name='naugh',RecordTypeId='012j0000000qRATAA2',self__c=aa.id);
insert bb;
system.debug('site'+bb.site);//Here it is showing null value
Account cc=[select Id, name,Site from account where Id =:aa.Id];
cc.Site ='istestchanged' ;
update cc;
update bb;
System.Test.stopTest();
}
 
Christopher McGeeChristopher McGee
I notice that in the line where you declare the Account bb you don't set the site field value:

Account bb= new Account(name='naugh', RecordTypeId='012j0000000qRATAA2', self__c=aa.id);

So bb.Site would have a null value when you reference it there.
Vj@88Vj@88
After insert you need to query that inserted record again to get the values from it.
Try

Account BBgetaccnt = [select id,site from account where id = :bb.id];
System.debug('site'+BBgetaccnt.site];

 
kumar palepukumar palepu
@christopher,In test class Self__c is a look up and in trigger i have written code like when we see look up in that lookup record which contains the Site value is automatically populated in the child records once insert the record.it  is working fine by manually doing  but here test class it showing null value.
@ Vj,
I have followed your guidence,but it is showing null value it self
Vj@88Vj@88
Can you post the trigger code?