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
Medhanie Habte 37Medhanie Habte 37 

Printing values in system.debug

Greetings all, I am adding a system.debug in my trigger and noticed that the values when running a debug are returing null.

My code is listed as 
 
 system.debug(mte.Service_Member__r.FirstName + ' and ' + mte.Lead_Supervisor__r.LastName + ' will be getting their member term evaluation on ' + mte.Date_of_Review__c.format() + 
                            ' for member term ' + mte.Member_Term__c);

The output appears as 

null and null will be getting their member term evaluation on 1/25/17 for member term a0Ig0000007iekyEAA

My goal is to get the output to appear as a value rather than null, the trigger works nicely no less, but still.

Hope it helps.

Joe and Jane will be getting their member term evaluation of 

Best Answer chosen by Medhanie Habte 37
Nisar799Nisar799

Hi Medhanie,

Yes output will be null, even records have data. Here is the explantion.
So In the trigger we have only values of object on which trigger is written, If try to access any parent values then it will return null.
 

system.debug(mte.Service_Member__r.FirstName + ' and ' + mte.Lead_Supervisor__r.LastName + ' will be getting their member term evaluation on ' + mte.Date_of_Review__c.format() + ' for member term ' + mte.Member_Term__c);
// So here you will get value only for
system.debug(mte.Service_Member__c );
If you have trigger on contact object and you want to see the account name and id where contact has account field some value.
 
System.debug('##> Account ID ' + con.Account.Id); // NULL
System.debug('##> Account Name ' + con.Account.Name); // NULL
System.debug('##> AccountId ' + con.AccountId); // have some value

Hope this will help you :)
Thanks
799 The Coder.

All Answers

FearNoneFearNone
hi medhanie,

It is null because it contains no data. Does mte has Service_Member__r.FirstName and Lead_Supervisor__r.LastName values? Also, if it does not have values, how will it be displayed?
Medhanie Habte 37Medhanie Habte 37
Good question, the records do have data actually, and I envision that no data will display if not. These naturally are required fields.
FearNoneFearNone
i see. from the way i see it, it both Service_Member__c and Lead_Supervisor__c have values, it should have been displayed. Try Service_Member__r.name and Lead_Supervisor__r.name if that will work.
If it will work, then there is no wrong with your code.
Nisar799Nisar799

Hi Medhanie,

Yes output will be null, even records have data. Here is the explantion.
So In the trigger we have only values of object on which trigger is written, If try to access any parent values then it will return null.
 

system.debug(mte.Service_Member__r.FirstName + ' and ' + mte.Lead_Supervisor__r.LastName + ' will be getting their member term evaluation on ' + mte.Date_of_Review__c.format() + ' for member term ' + mte.Member_Term__c);
// So here you will get value only for
system.debug(mte.Service_Member__c );
If you have trigger on contact object and you want to see the account name and id where contact has account field some value.
 
System.debug('##> Account ID ' + con.Account.Id); // NULL
System.debug('##> Account Name ' + con.Account.Name); // NULL
System.debug('##> AccountId ' + con.AccountId); // have some value

Hope this will help you :)
Thanks
799 The Coder.
This was selected as the best answer