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)
Application__c:Master Detail Relationship

Application__c related to App__c

App__c (Object)

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.

  • Just to be sure - App__c is master-side in this relationship? – Artur Kępczyński Jun 5 '14 at 6:57
  • yes App__c is the master side – user8737 Jun 5 '14 at 8:32

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:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.