Below are the objects like Account, Contcat, Object1__c, Object2__c and Object3__c. Each obejct have some different field values like shown below.
Account acc = new Account();
acc.name='Test';
acc.Code__c = '0011';
insert acc;
Contcat con = new Contcat();
con.Lastname='Test_name';
insert con;
Object1__c Obj1 = new Object1__c();
Obj1.Account_ID__c = acc.Id;
Obj1.Contact_ID__c = con.id;
insert Obj1;
Object2__c Obj2 = new Object2__c();
Obj2.Field1__c = 'Test1 Value';
Obj2.Field2__c = 'Test2 Value';
Obj2.Field3__c = 'Test3 Value';
insert Obj2;
Object3__c Obj3 = new Object3__c();
Obj3.Object2__c = Obj2.Id;
Obj3.Object1__c = Obj1.id;
But my issue is, I want to assign a value for the field Code__c using Object3(like shown in below).
Obj3.Object1__c.Account_ID__r.Code__c = 'AAABBB';
It does not give me any issue while saving, but while I am running the code, Its giving bellow error
Attempt to de-reference a null object
Am i missing anything here? Can some one help me here please.
Contcat
instead of the standardContact
?