[SalesForce] Soql inner join (Apex)

Morning guys, I am having a issue, I need to make a inner join in soql…
Example:

  • Process instance( table1)
  • Process instance step(table 2)

I need to create a table mixing both tables, Id tabel 1 is process instance id in the 2, Table 1 primary key is a forien Key in table 2…

But soql will not support joins for tables
I have to write a complete code for this… do you know any other way apart form Apex class?

Best Answer

So Lets Assume this is your Process Table 1

Id(Primary Key),Name,Description__c,Other_Fields__c

And Process Table 2 Schema Looks like this

Id(Primary Key),Name,Process_Table1__c(Lookup / foreign Key to Table 1), Other_Fields__c

Here you can use Join, to get Parent_table1__c Fields querrying the Process_Table2__c, Its called as child-to-parent traversal

SELECT Id,Name,Process_Table1__r.Name,Process_Table1__r.Description FROM Process_Table2__c

Also, Another kind of join is Parent To child, Inner Querry, which allows yoqueryuerry child for a particular parrent

SELECT Id,Name,Description__c,(SELECT Id,Name FROM Process_Table2__r) FROM Parent_table1__c

Src: https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships_understanding.htm

Related Topic