4

I am currently learning Salesforce and Apex etc and I am stuck trying to write a trigger which contains a query. Here are my two custom objects:

Student__c (Object)
Nickname__c
Email__c
Application__c:Master Detail Relationship


Application__c related to App__c

App__c (Object)
Name

So, now I want to write a query that fetches the pairs of (Email__c and the correct App__c.Name which is related to the student). So far I have

Select Email__c, Name FROM Student__c, App__c WHERE Application__r.Name = App__c.Name

This is not working, but I cannot quite get my head round querying a Master Detail Relationship. I am sure it's super simple and there is just one little thing I am missing.

2
  • Just to be sure - App__c is master-side in this relationship? Jun 5, 2014 at 6:57
  • yes App__c is the master side
    – user8737
    Jun 5, 2014 at 8:32

1 Answer 1

2

If I understand your problem, you just want do something like this?

Student__c student = [Select Email__c, Name, Application__r.Name 
                      FROM Student__c];
System.debug(student.Application__r.Name + '   =>  ' + student.Email__c);

This will return you Application Name and Student eMail.

BTW : In SOQL you can't compare 2 fields :(

Check this if you want start your work with salesforce SOQL:

http://www.salesforce.com/us/developer/docs/officetoolkit/Content/sforce_api_calls_soql.htm

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .