+ Start a Discussion
Pooja Singh 21Pooja Singh 21 

Unable to get a field's value of Master object from Custom Detail object.

Hi All,

I have written a small trigger which does not display the value from Line 6.

trigger TypeOfLienForNVOnProperty on Property__c (before insert, before update, after insert, after update) { 
    
    for(Property__c p : Trigger.new){
        if(p.Property_State__c != null && p.Property_State__c != '' && p.Property_State__c == 'NV'){
            system.debug('Value in State-->' + p.Property_State__c);
            system.debug('Value in Type of Loan-->' + p.Opportunity__r.Type_of_Loan__c);
            
            if(p.Opportunity__r.Type_of_Loan__c != null && p.Opportunity__r.Type_of_Loan__c != 'Principal & Interest'){
                system.debug('Value in Type of Loan-->' + p.Opportunity__r.Type_of_Loan__c);
                p.addError('For Nevada, only "Principal & Interest" is allowed as Type of Lien.');
            }
        }

Please help to let me know where I did wrong.
Best Answer chosen by Pooja Singh 21
Shrikant BagalShrikant Bagal
The Trigger.New just have Object Values not Parent or relational Object values. if you wants it, you have to query in trigger.


if its resolved your issue,please mark as best answer so it will help to other who will serve same problem.
​Thanks! 

All Answers

Shrikant BagalShrikant Bagal
The Trigger.New just have Object Values not Parent or relational Object values. if you wants it, you have to query in trigger.


if its resolved your issue,please mark as best answer so it will help to other who will serve same problem.
​Thanks! 
This was selected as the best answer
Pooja Singh 21Pooja Singh 21
It worked after using a SOQL query. Thank you so much Shrikant.