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
Monishan MMonishan M 

Salesforce relationship query not fetching result

Hi,

I have written below trigger. But I am not getting any value in the query list. The issue occurs when I give Account_vod__r.country_code_az__c IN :CountryCodes. Can you please let me know why this occurs?

trigger UpdateTA on Survey_Target_vod__c (after update) {

Management_Setting__c AZMEE =Management_Setting__c.getOrgDefaults();
List<String>Countrycodes = new List<String>();
If(AZMEE.Spkr_Therapy_Areas__c!=null){

List<String>Countrycodes = AZMEE.Spkr_Therapy_Areas__c.split(';');
system.debug('hello' +Countrycodes);

}


List<Survey_Target_vod__c> relatedsurveytarget = [SELECT Id,Therapy_Area__c,Submitted_DateTime_vod__c,Name,Account_vod__c,Survey_vod__r.Product_vod__c,Segment_vod__c,
                                                   Survey_vod__c,LastModifiedDate,Survey_vod__r.Detail_Group_vod__c,
                                                   Survey_vod__r.Product_Metric_AZ__c,Survey_vod__r.Product_Metric_AZ__R.Field_Name_AZ__c FROM Survey_Target_vod__c
                                                   WHERE id IN :Trigger.New and Status_vod__c ='Submitted_vod' 
                                                   and Survey_vod__r.Profiling_Survey_AZ_RU__c=True and Survey_vod__r.Profiling_Type_AZ__c='Question Score Based'
                                                   and Account_vod__r.Country_Code_AZ__c IN :Countrycodes
                                                   
                                                    ];
                                                                                                      
                                                    
system.debug('countrylist' +relatedsurveytarget);

The List relatedsurveytarget is empty when checked in debug logs. But i have a record which satisfies all the above condition but still not getting fetched in this query.

Thanks
AnudeepAnudeep (Salesforce Developers) 
Hi Monishan, 

Can you try using a hardcoded value instead of a bind variable (:CountryCodes). Please use the country_code_az__c value from the record

Please let me know if your query fetches the result that way