You need to sign in to do that
Don't have an account?
timomer
Grab data from a different object - easy question!?
Hi,
Im new to apex and just starting to pick it up, so sorry if this is a simple question.
I have a custom object on Opportunities, when saving this custom object I need to grab some data from the Opportunity.
For example I need to grab the UserName of the owner of the Opportunity, how would I do this? From the custom object I can grab the Opportunity ID (chat.Oppertunity__c) but not sure what to do with it next?
Thanks in advance for your help!
tim
Query for the related data.
Opportunity o = [Select o.Owner.Username, o.OwnerId From Opportunity o where o.Id = :chat.Opportunity__c];
String ownerUsername = o.Owner.Username;
All Answers
Query for the related data.
Opportunity o = [Select o.Owner.Username, o.OwnerId From Opportunity o where o.Id = :chat.Opportunity__c];
String ownerUsername = o.Owner.Username;
was looking for some example query as I thought that would be the way but could not find anything that had a detailed explanation on how it would work.
One quick question...
below you use "o.Owner.Username" that works perfectly, but, in the Eclipse IDE I do not get this listed as an option to select after o. - do I have a missing configured? Or is the IDE limited and this information is listed elsewhere?
many thanks!
tim