function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jisakc1jisakc1 

I need query help!

I have a custom object, a junction table and Accounts  I need to pull from the junction table.   The message is the it doesn't understand the relationship reqCH in the query.  What am I missing here????

Here is the query ( stripped out pieces so syntax may not be right but the piece in bold is what causes the error because if I take it out I can save.):

DCS_Request__c reqCH = [SELECT Id, CRM_Account__c, CRM_Account__r.CRM_Parent_Account_Ultimate__c, CRM_Account__r.CRM_Credit_Parent__c
           ,CRM_Account__r.ParentID,  CRM_Account__r.CRM_Credit_Ultimate__c
            FROM DCS_Request__c WHERE ID =: req.Id LIMIT 1];
    
      
       j = [SELECT Name, ,CRM_ChildAcct__c, CRM_DCS_Request_ID__c
              ,  CRM_Allow_Parent__c, CRM_Allow_Ult_Parent__c,  CRM_Account_ID__c, CRM_Account_ID__r.Name
              , CRM_Account_Id__r.ParentId, CRM_Account_Id__r.CRM_Parent_Account_Ultimate__c
              , CRM_ChildAcct__r.ParentId, CRM_ChildAcct__r.CRM_Parent_Account_Ultimate__c
              , CRM_DCS_Request_ID__r.CRM_Account__c, CRM_DCS_Request_ID__r.Id
             
              FROM CRM_Junctions__c  WHERE (
              ((CRM_ChildAcct__c =:reqCH.CRM_Account__c)
              OR ( CRM_Account_ID__c =: reqCH.CRM_Account__c AND CRM_ChildAcct__c = null)
             
              OR (CRM_Account_ID__c =: reqCH.CRM_Account__r.ParentID and CRM_ChildAcct__c = null and reqCH.CRM_Account__r.CRM_Credit_Parent__c = true)
              
             
              AND RecordType.Name = 'Junction' ) order by LastModifiedDate DESC Limit 10];
ShashForceShashForce
Hi,

Please try by removing "reqCH." in the bold part. Something like this:
    OR (CRM_Account_ID__c =: reqCH.CRM_Account__r.ParentID and CRM_ChildAcct__c = null and 
CRM_Account__r.CRM_Credit_Parent__c = true)

If this answers your question, please mark this as the Best Answer for this post, so that others can benefit from this post.

Thanks,
Shashank

jisakc1jisakc1
That didn't work. I ended up having to make the query very general and then loop thru the rows to decide which ones I wanted to use. Thanks, Kathy Carter | Systems Analyst 479.361.7646 (O) | 479.263.2627 (C) J.B. Hunt Transport, Inc. | Our business is moving yours.? Single Source | Intermodal | Dedicated | Final Mile | Truckload | LTL | Refrigerated | Flatbed