+ Start a Discussion
pierrefrazny.ax358pierrefrazny.ax358 

Browse a relationship to retrieve information on parent record

I have a lookup to Contact on an record o and would like to retrieve the value of a field on contact. This syntax does not seem to work:

o.Contact__r.number__c

Do I really have to run a SOQL query the information? 

Thanks

Pierre 

bob_buzzardbob_buzzard
Can you clarify "does not seem to work", i.e. do you get an error, is the value null etc
pierrefrazny.ax358pierrefrazny.ax358

The value is always null.

Thanks 

Message Edited by pierrefrazny on 01-19-2010 04:57 AM
bob_buzzardbob_buzzard

Can you tell us how you are populating your object?  I.e. is it a soql query?

 

Posting code always helps. 

pierrefrazny.ax358pierrefrazny.ax358
Here is the code. I am not trying to populate the field but retrieve the value (r.Contact__r.Number__c).  I am noticing that the value of r.Contact__r.Number__c  retrieved via this code is always NULL regardless of what the actual field value is. This makes me think I am not doing it correctly.
 
 

trigger RegistrationRepeat on Registration__c (before insert, before update) { if(Trigger.IsInsert || Trigger.IsUpdate){ for (Registration__c r : Trigger.new) { if (r.Status__c == 'Completed'){ if(r.Contact__r.Number__c == NULL) {r.Repeat__c = 0;} else {r.Repeat__c = 1;} } } }}

 

 Thanks
XactiumBenXactiumBen
I don't think you can get the parent record information from trigger.new records in a trigger.  What you will have to do is to either do an after update/insert trigger then requery your Registration__c objects from the database (rubbish I know!) or query your list of contacts and try to match the id in r.Contact__c to your contact records.