You need to sign in to do that
Don't have an account?
Namit Pal
Unable to write an SOQL Query for the junction Object?
Hi everyone. I have a junction object called Project Mapping which has a lookup to a custom object- 'Project' and a lookup to the Standard Object- 'User'. The junction object is the link between the two objects which is mapping the objects.
My objective is to create a SOQL query to retrieve the Projects related to a particular user, specifically the user who has signed in.
I am struggling a lot to create that query. Can someone please help me with that query?
May I suggest you please refer the below link for reference.
- https://salesforce.stackexchange.com/questions/73502/soql-best-practices-with-multiple-junction-objects
- https://developer.salesforce.com/forums/?id=906F00000008pXiIAI
Hope it will be helpful.Please mark it as best answer if the information is informative.so that question is removed from an unanswered question and appear as a proper solution.
Thanks
Rahul Kumar
If you just need project details, you may try the below one and let me know
SELECT
Project, Project__r.Project_Name, Project__r.StartDate -- May add whatever fields you need from Project object.
FROM
Project_Mapping__c
WHERE
User =:UserInfo.getUserId() --Assume User field in Project Mapping junction object is the User ID let me know if not .
<pre>
List<Project__c> projects =
[ SELECT Id, // other fields here
FROM Project__c
WHERE Id IN (SELECT Project__c FROM Project_Mapping__c WHERE User__c = :UserInfo.getUserId())
];
</pre>