I have below trigger block. I am getting null values for dsrl.Related_Opportunity_del__r.Business_Group__c.

if(Trigger.isbefore && (Trigger.isInsert|| Trigger.isUpdate)){
        System.debug(':::::inside Isbefore::::');
            for(Deal_Support_Request_del__c dsrl : Trigger.new){
                System.debug(':::::inside for loop::::'+Trigger.new);
                System.debug(':::::inside for loop::::');
                System.debug(':::::value of recurrence::::'+recurrence);
                System.debug(':::::value of recordtype::::'+dsrl.recordTypeID);
                System.debug(':::::value of opp id ::::'+dsrl.Related_Opportunity_del__c);
                System.debug(':::::value of business group::::'+dsrl.Related_Opportunity_del__r.Business_Group__c);
                if(!recurrence && (dsrl.RecordtypeId == dsrSORequestRecordTypeId) && dsrl.Related_Opportunity_del__r.Business_Group__c=='Ultrasound'){
                System.debug(':::::value of GTM::::'+dsrl.GTM_Region__c);

The value of "dsrl.Related_Opportunity_del__c" is coming correctly as id but for dsrl.Related_Opportunity_del__r.Business_Group__c it is giving null values.When i queried in soql using below query i am able to get values.

SELECT Related_Opportunity_del__r.Business_Group__c FROM Deal_Support__c where id='a0S7A000000dT9r'
  • 1
    Your SOQL is working off 'Deal_Support__c' while your trigger.new() is over 'Deal_Support_Request_del__c'. Are you mixing up objects? – TSmith Apr 20 '17 at 11:55

Data in related objects (like your case, dsrl.Related_Opportunity_del__r.Business_Group__c) is not available in trigger context variables.

Assuming that this code is called via a trigger on Deal_Support_Request_del__c, dsrl.Related_Opportunity_del__c is available because that is a field on your Deal_Support_Request_del__c object.

dsrl.Related_Opportunity_del__r.Business_Group__c, on the other hand, is related data. It's the Business_Group__c field on what I assume is the Opportunity object.

To get dsrl.Related_Opportunity_del__r.Business_Group__c (a field on a record related to a record on the object your trigger is on), you'll need to perform a query.

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.