+ Start a Discussion

Getting CrossReference object values on Trigger.

Hi to all,
I have two custom objects providerActivity & batch.
The Batch linked to lookup on Provideractivity object.
I write a trigger on Provider Activity object on Before Insert time.
I want the the Batch object symbolicname field(objProviderActivity.BatchID__r.ProviderSymbolicName__c).But I insert the record on providerActivity record the symbolic name shows null and the objprovider size is 0.
My coding are,

trigger Activity on ProviderActivity__c (before insert) { for(ProviderActivity__c objProviderActivity : Trigger.New) { system.debug(objProviderActivity.BatchID__r.ProviderSymbolicName__c); Account[] objProvider = [select id,name,ActivityStatusDictionary__c,PaymentStatusDictionary__c,ProviderSymbolicNames__c from account where ProviderSymbolicNames__c Like : (objProviderActivity.BatchID__r.ProviderSymbolicName__c+',') OR ProviderSymbolicNames__c Like : (',' + objProviderActivity.BatchID__r.ProviderSymbolicName__c + ',') OR ProviderSymbolicNames__c Like : (','+ objProviderActivity.BatchID__r.ProviderSymbolicName__c) ]; system.debug(objProvider.size()); if(objProvider.size() >0) { //My Functions. } } }


the Cross reference is working on before Insert???
the cross reference is not working.My coding is correct or not???
No relationships are populated in triggers, only the ID fields that establishes them.  So you need to iterate over the records in the collection generating another collection for the unique related object IDs and after your loop, query the related table with those collected (using the "IN" operator). And finally after the query iterate back over the records in the trigger correlating the values to process your logic as necessary.