0

I am using salesforce sdk. I want to fetch records using inner join. I have 2 tables Campaign and Attachment. Each Campaign has a single Attachment.

SELECT Campaign.CustomerName, Attachment.Body
FROM Campaign
INNER JOIN Attachment
ON Campaign.Id = Attachment.ParentId

I'm referring following link. But its not useful i think

https://sivatejaforce.wordpress.com/2011/02/11/a-deeper-look-at-soql-and-relationship-queries/

1 Answers1

0

Are you building a SQL Query or a SOQL query?

If this is a SOQL query then SQL JOIN does not exist.

What you need is:

SELECT CustomerName, (SELECT Body FROM Attachments) FROM Campaign

This will do a "child" query on a the attachment relationship field.

To give you an example of the return structure for this data as JSON, it would look like this:

{
    "CustomerName":"SomeName",
    "Attachments": [ { "Body":"someblob" }, { "Body":"someOtherBlod" } ]
}
spenibus
  • 4,339
  • 11
  • 26
  • 35
  • If I am using this query. It is returning Didn't understand relationship 'Attachment' in FROM part of query call. – Gurpreet Singh Oct 11 '15 at 05:27
  • Salesforce does not join tables. It returns related objects as child properties. In this case attachments would be a property of the Campaign object (a list of attachments). I am not sure how this looks when it is de-serialized in java, however the serialized version(JSON) should look like my example. – Dennis Mohan Oct 12 '15 at 20:51