function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
zeezackzeezack 

Join tables?

I've managed to extract information perfectly fine for one table...its quick and dynamic. Although one of the fields it returns is an index field for another table....is there an easy way to pull out a name field from a foreign table instead of just its id?

 

aka

 

table 1

 

IdNamePrimary_Account_Holder__c
a0C20000002uh8HEAQMCS-CLAIM-cvcvc001200000dfgfdgfdAAH

 

 

table2

 

IdName
001200000dfgfdgfdAAHVIVIENNE BLAKE

 

 

 

How can I return it so I have

 

 

table 1

 

IdNamePrimary_Account_Holder__c
a0C20000002uh8HEAQMCS-CLAIM-cvcvcVIVIENNE BLAKE

 

 

jack_lincon_zhujack_lincon_zhu
Maybe you can get some help from custom reports type.You can implement the result use custom reports type.
SuperfellSuperfell
select id, name, Primary_Account_Holder__r.name from whatever__c
zeezackzeezack

So how would that work for this

 

 SELECT Id, Name, Primer_id from Claim_c WHERE Name IN ('My-claim2','My-claim3452','My-claim2345','My-claim525');

 

 

 

now primer_id is actually the index of say Account

 

SELECT Id, Name from Account WHERE Name IN ('a34234234','afgbgfhgfhgf');

SuperfellSuperfell

exactly the same way (see the docs on SOQL-R in the api docs).

 

SELECT Id, Name, Primer__r.name from Claim_c WHERE Name IN ('My-claim2','My-claim3452','My-claim2345','My-claim525'); 

zeezackzeezack

How does it know to get the Name value from Account table using the Primer__r id?

 

how come there is no From Claim__c, Account or something?

SuperfellSuperfell

SOQL ain't SQL.

 

it knows the primer__r relationship is a relationship to account (using the primer__c foreign key field), this is covered in the SOQL section of the API docs. 

zeezackzeezack

Sorry man. I've not got this to work.

 

 I've caught the field

Primary_Account_Holder__c

 

 

and 

placed it now as 

 

Primary_Account_Holder__r.name

 

and it just puts blanks in place.

 

 

SuperfellSuperfell
And your code looks for the nested name field ?
zeezackzeezack

SELECT Id,Name,Primary_Account_Holder__r.name,Audit_Result__c from Claim__c WHERE Name IN ('MCS-CLAIM-34016','MCS-CLAIM-343416','MCS-CLAIM-56565016')

 

 

 I can not tell, but where Primary_Account_Holder__c returned a value Primary_Account_Holder__r.name returns nothing.

 

 

SuperfellSuperfell

Primary_Account_Holder__c would be returned as a direct value, where as the relationship is a nested structure, e.g.

 

<record>

<id>1111</id> 

<foo>12344</foo>

</record>

vs

<record>

 <id>1111</id> 

 <foo__r>

   <name>bob</name>

 </foo__r>

</record> 

 

However you're accessing these results needs to take that into account.