Search code examples
sqlappendsalesforceleft-joinsoql

Salesforce append __r error (join 3 tables)


I have three tables :

Opportunity_Buy__c,
Campaign__c,
Internal_Line_Item__c

and I am trying to join them on salesforce. The relationships (join on) will be :

Opportunity_Buy__c.AAAAA = Campaign__r.AAAAA,
Internal_Line_Item__r.OpportunityBuy__c = Opportunity_Buy__c.id 

My script is the following :

SELECT
 Media_Code__c,
 Special_Product__c,
 Buy_Type__c,
 Start_Date__c,
 End_Date__c,
 Gross_Cost__c,
 Rate__c,
    (SELECT Partner_Name__c, AppNexus_IO__c, Goal__c, Goal_Details__c, Gross_CPM__c, GROSS_COST2__c, Name FROM Internal_Line_Item__r),
    (SELECT AAAAA FROM Campaign__r)
FROM Opportunity_Buy__c
WHERE AAAAA IN (SELECT AAAAA FROM Campaign__r)
AND id IN (SELECT OpportunityBuy__c FROM Internal_Line_Item__r)

and I am getting an error :

Didn't understand relationship 'Internal_Line_Item__r' in FROM part of query call.

I don't understand what is wrong. I am trying this and I am still getting an error :

    SELECT
 Media_Code__c,
 Start_Date__c,
 End_Date__c,
    (SELECT Partner_Name__c, Name FROM Internal_Line_Item__r)
FROM Opportunity_Buy__c

Solution

  • Please read this documentation about Relationship Queries in Salesforce.

    This article is exactly what you need.

    You need to replace Internal_Line_Item__r and Campaign__r in this part

    (SELECT Partner_Name__c, AppNexus_IO__c, Goal__c, Goal_Details__c, Gross_CPM__c, GROSS_COST2__c, Name FROM Internal_Line_Item__r),
    (SELECT AAAAA FROM Campaign__r)
    FROM Opportunity_Buy__c
    

    with what you have in Child Relationship Name for these relations.

    enter image description here

    EDIT================>>>

    How to find Admin interface:

    • Classis interface:

    enter image description here

    • Lightning interface:

    enter image description here

    So, in Salesforce you can't create objects(tables) directly from SOQL. You have to use web user interface to deal with creation of custom objects(tables) & custom fields(columns)

    Also I found good article which can help here enter image description here