Parent object detail vs relationship(alias) object debug values

i have a Story, that has a ‘references’ relationship to referenceImage.
In the debugger, after reading a Story, I see the referenceImage data, including the target URL I’m trying to use.

But on the next line, I debug just that referenceImage element, and get nothing.

Why?

I suspect that something is reseting the referenceImage object. Ping me a link and I can take a look.

refreshed background here:

in initialize, we have this:

debug('this.story', this.story);
debug('this.story.referenceMedia', this.story.referenceMedia);

where ‘referenceMedia’ is a ‘references’ relationship


https://app-me-us-kirk.apexdesigner.app/stories2/1
Just load the page with debug string below and look at the first 2 lines of Console

localStorage.setItem(‘debug’,localStorage.getItem(‘debug’) ? localStorage.getItem(‘debug’) +‘,Story2:’ : 'Story2:’); localStorage.getItem(‘debug’)

Your debug statements are in the initialize method. That is called immediately when the page is loaded. Most importantly, that is called before the read of the data on the page is completed. The debug entries in the console are references and therefore represent what the current state of the object is - not what the state was when the debug line was written.

To correctly see what came back from the API, you should put these debug entries in a method that is called after read of the property.

That still may not be right is something in the page later causes it to become undefined. To detect that, you could add “%” to the end of your debugs like this:

debug('this.story %j', this.story);
debug('this.story.referenceMedia %j', this.story.referenceMedia);

That will convert the object to a json string at that moment in time. If it looks ok right after the read is complete, then do the same %j debugs at later points to see when becomes undefined.

As a general rule of thumb, when you are debugging a timinig issue, use %j for objects.

one further clarification question. you said:

To correctly see what came back from the API, you should put these debug entries in a method that is called after read of the property.

but since you can’t choose when a method is executed (except on load, or unload), I supposed you could define a Service…or Behavior on the business object side and make it an event handler…but then it’s not specifically in the context of the Page…

What is the best practice here for ensuring you can see what data the page is working with, is there a pattern to follow generally?

The “After Read” I was referring to is here: