0

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
Datacrawler
  • 2,780
  • 8
  • 46
  • 100

1 Answers1

1

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

Pavel Slepiankou
  • 3,516
  • 2
  • 25
  • 30
  • Hi again. The code is fine I guess. I just have to replace the names you mentioned with the relationship names. I have to create a relationship between the tables. I will try to figure out how to do it because I am not familiar with salesforce. – Datacrawler Feb 10 '16 at 09:19
  • @ApoloRadomer I guess that all relationship should already exists. Go to Setup - Create - Objects - select `Opportunity_Buy__c` object and find fields with for these relations – Pavel Slepiankou Feb 10 '16 at 09:25
  • As I have never dealt with Salesforce before (can't say I really like it), I did not know how to do that. I tried to create a new account on the workbench as I no longer have access but I want to learn how to deal with this problem just in case for the future. I tried to create 3 tables but it was impossible. I uploaded the date from the Opportunity to the "Account" but it was impossible to do the same with Campaign and Internal Li Table. There is no way to create custom tables! So I cannot test the mapping. – Datacrawler Feb 11 '16 at 15:27
  • @ApoloRadomer Salesforce objects the same thing as tables in relational db. To create a new table you need to login into Salesforce web interface and open admin part. Go through these guides https://developer.salesforce.com/trailhead/module/data_modeling and see edit on the answer – Pavel Slepiankou Feb 12 '16 at 04:49