1

I have a requirement to create a report. I have three Objects : Contact, Order and Lead.

Order is lookup to contact. Lead has no relation with any of these.

I need to create a report with some fields of every Objects. I am looking for SOQL OR is there any other way around.

  • Anybody has any idea about this ? – SFDC Mafia - VIC Sep 3 '15 at 3:05
  • Can you provide a sample output of how should your report look ... Just specifying u want to display unrelated data is not descriptive – Amr Ibrahim Sep 3 '15 at 8:29
2

It seems strange that you want to create a report via SOQL. I assume you mean to create a report to export via the REST API (like Workbench).

1) You won't be able to achieve this via SOQL because SOQL statements must traverse a valid relationship. The documentation here gives more information. So you could use SOQL to get data from Order and Contact records because there is a relationship between these two objects, but you would not be able to traverse anywhere to get to the Lead object (since there is no relationship between the aforementioned objects and the Lead object).

When you are traversing between objects via SOQL, you will either be using downward or upward traversal. This is a good link to see how this can be achieved.

2) However, you will be able to achieve this via a Joined report type via the UI. As this is achievable via the UI, this doesn't require any SOQL or SOSL. The benefit here is that you can save this report and save it to a report folder and then distribute the report link to your colleagues who have a Salesforce license.

3) If you really did want to use SOQL to create a report, then you could create a relationship (lookup relationship between Lead and Contact may be preferable). So the Lead would be related to the Contact via an optional lookup, and this would mean it would be possible to traverse between those three objects. Or another way would be to have 'Order' as the junction object, allowing the Order object to be related to n number of Leads and n number of Contacts.

Hope this helps.

Thanks,

  • Thanks mate for your description. I got that. There is no way to fetch records if there is no relations between objects. – SFDC Mafia - VIC Sep 3 '15 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.