You need to sign in to do that
Don't have an account?
Tanner Russell
Why is this field showing null even after adding a reference to the id
Account la_test = new Account(Name='Test'); insert la_test; Contact lcon_test = new Contact(LastName='Test', Accountid=la_Test.id, Email='test@test.com'); insert lcon_test; location__C lloc_test = new Location__C(name = locName, site_wf__c = site); insert lloc_test; RecordType rec = [SELECT Id,Name FROM RecordType WHERE SobjectType='Case' and name = :record]; Case lc_test = new Case(Subject='This is a test ', Accountid=la_Test.id, Status='New', RecordTypeId=rec.id, Contactid=lcon_test.id, Location__c= lloc_test.id, Notify_contact__c = true); //for trigger testing insert lc_test;If I do a lookup query on the location id being passed into case its name value is populated but when I do lc_test.location__r.name it shows as null (location__c being a lookup field) does anyone know what im doing wrong?
// You need to query related field to get value like below
Case caseObj = [select id, location__r.name ,location__r.site_wf__c from Case where id =:lc_test.id ];
System.debug(caseObj.location__r.name);
System.debug(caseObj.location__r.site_wf__c);
Please try below test class
All Answers
I added the debug lines to clear things up
// You need to query related field to get value like below
Case caseObj = [select id, location__r.name ,location__r.site_wf__c from Case where id =:lc_test.id ];
System.debug(caseObj.location__r.name);
System.debug(caseObj.location__r.site_wf__c);
Please try below test class