Here is my problem. I'm trying to establish a parent child relationship like the below and want to use the OBJECT reference and NOT the ID reference.
I have created a custom lookup field on Contact called MyAccount that looks up to Account and want to populate that field using the object reference.
Account a = [SELECT ID, NAME FROM Account WHERE NAME = 'TEST ACCOUNT' LIMIT 1]; Sobject c = Schema.getglobalDescribe().get('Contact').newSObject(); c.put('lastname', 'sobject test'); c.putSobject('myaccount__r', a); insert c;
When I query the contact after it's being inserted, however the reference is NOT populated. It's showing as NULL. How to fix this? Again, I want to use parent record reference and NOT ID reference.
Note: this works for Standard fields - for example if I do something like.
c.putSobject('Account', a) - this works perfectly