0

In my AfterUpdate trigger, I check:

System.debug('fieldA is ' + processingFees.get(o.ID).fieldA + ' for ' + processingFees.get(o.ID).id);    
if(processingFees.get(o.ID).fieldA >0){
                        processingFees.get(o.ID).fieldA = processingFees.get(o.ID).fieldA - valueA;
                    }

And my code in the conditional wasn't happening even though I populated fieldA. So, I added that print statement at the top to see for myself the Value and the ID of the record. Maybe somehow at this point in the code, it changed to 0, I thought.

The debug said fieldA is NULL for (the ID here) . I knew I populated it, so I copied the ID, put it in my browser to find the record, and it in fact was populated!

What reason might there be for thies field being NULL in the code when it's actually populated?

  • the field is Currency
1

The issue you are facing here seems to be:

Trying to access a field that was not queried.

For that explanation, you can refer this post: Test data returning Null.The answer/conversation by Santanu Boral states that well enough.

For your issue, you could try something like this:

String tempVar = [Select currencyField From whateverObject Where Id =: whatever.Id].currencyField;
System.debug('Currency Field value:' +tempVar);

Now that you have queried the actual value of the required Currency field, you may use is wherever needs to be.

| improve this answer | |
0

Interesting - essentially, it was because I wasn't querying for it (though I thought I was...will expand), but I know why it didn't give the "without querying the requested column" type error.

So, first things first, a fail on my part. I added the field into the Query, saved, and I think tested before it actually saved it so it didn't work...and I removed it to re-design, and never put it back in. So, ultimately, a silly issue, my fault there.

The interesting thing I wanted to share was why this didn't cause the SOQL query error if that was in fact the issue.

I essentially wanted to grab an object and update it without querying for it (in a trigger loop) so in my crafty little mapping data structure, instead of querying for it, I realized you can, with the ID, just do

OrderItem oi = new Order(ID = oi.ID . . Name = ...); and it recreates it . . . in a way? I never fully understood why you can do this, but I loved it.

So...interestingly, even though it maintains to be the same Record even though it's a "new" record. . . it wasn't that I didn't query for it...it was actually NULL because I never instantiated it in this "new" record of it

Maybe this is really obvious but I thought it was interesting how you can make "new" records with the existing ID...even the fields I didn't instantiate in that line still ended up staying because it's the same record, so I figured that field would remain without including it in the instantiation.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.